本文整理汇总了Java中net.dv8tion.jda.core.exceptions.ErrorResponseException类的典型用法代码示例。如果您正苦于以下问题:Java ErrorResponseException类的具体用法?Java ErrorResponseException怎么用?Java ErrorResponseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ErrorResponseException类属于net.dv8tion.jda.core.exceptions包,在下文中一共展示了ErrorResponseException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: closeVote
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
private void closeVote(GuildMessageReceivedEvent event){
Message message = event.getMessage();
User author = event.getAuthor();
if(!polls.containsKey(event.getGuild())){
message("There is currently no poll running on this guild", Color.red);
return;
}
Poll poll = polls.get(event.getGuild());
if(core.permissionHandler.check(2,event)){
return;
}
polls.remove(event.getGuild());
channel.sendMessage(getParsedPoll(poll, event.getGuild()).build()).queue();
message(":white_check_mark: Poll was closed by" + event.getAuthor().getAsMention(), new Color(0x3AD70E));
Message pollmsg = channel.getMessageById(String.valueOf(poll.pollmsg)).complete();
try {
pollmsg.delete().queue();
} catch (ErrorResponseException e){
//This is an empty Catch Block
}
}
示例2: getJdaRestActionFailureHandler
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
public static Consumer<Throwable> getJdaRestActionFailureHandler(final String info, final ErrorResponse... ignored) {
final LogTheStackException ex = new LogTheStackException();
return t -> {
ex.initCause(t);
if (t instanceof ErrorResponseException) {
final ErrorResponseException e = (ErrorResponseException) t;
// Metrics.failedRestActions.labels(Integer.toString(e.getErrorCode())).inc();
if (Arrays.asList(ignored).contains(e.getErrorResponse())
|| e.getErrorCode() == -1 //socket timeout, fuck those
) {
return;
}
}
log.error("{}\n{}", info, t.getMessage(), ex);
};
}
示例3: complete
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
/**
* Blocks the current Thread and awaits the completion
* of an {@link #submit()} request.
* <br>Used for synchronous logic.
*
* @param shouldQueue
* Whether this should automatically handle rate limitations (default true)
*
* @throws RateLimitedException
* If we were rate limited and the {@code shouldQueue} is false
* <br>Use {@link #complete()} to avoid this Exception.
*
* @return The response value
*/
public T complete(boolean shouldQueue) throws RateLimitedException
{
try
{
return submit(shouldQueue).get();
}
catch (Throwable e)
{
if (e instanceof ExecutionException)
{
Throwable t = e.getCause();
if (t instanceof RateLimitedException)
throw (RateLimitedException) t;
else if (t instanceof PermissionException)
throw (PermissionException) t;
else if (t instanceof ErrorResponseException)
throw (ErrorResponseException) t;
}
throw new RuntimeException(e);
}
}
示例4: update
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
public void update(RestJDA restJDA, Database connector, Instant now)
{
restJDA.editMessage(channelId, messageId, render(connector.settings.getSettings(guildId).color, now)).queue(m -> {}, t -> {
if(t instanceof ErrorResponseException)
{
ErrorResponseException e = (ErrorResponseException)t;
switch(e.getErrorCode())
{
// delete the giveaway, since the bot wont be able to have access again
case 10008: // message not found
case 10003: // channel not found
connector.giveaways.deleteGiveaway(messageId);
break;
// for now, just keep chugging, maybe we'll get perms back
case 50001: // missing access
case 50013: // missing permissions
break;
// anything else, print it out
default:
LOG.warn("RestAction returned error: "+e.getErrorCode()+": "+e.getMeaning());
}
}
else
LOG.error("RestAction failure: ["+t+"] "+t.getMessage());
});
}
示例5: closeVote
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
private void closeVote(CommandManager.ParsedCommandInvocation parsedCommandInvocation) {
Message message = parsedCommandInvocation.getMessage();
User author = message.getAuthor();
if (!polls.containsKey(message.getGuild())) {
message.getTextChannel().sendMessage(EmbedUtil.error("No poll", "There is currently no poll running on this guild").build()).queue(msg -> msg.delete().queueAfter(10, TimeUnit.SECONDS));
return;
}
Poll poll = polls.get(message.getGuild());
if (message.getAuthor().equals(poll.getCreator(message.getGuild()))) {
message.getTextChannel().sendMessage(EmbedUtil.error("No permission", ":warning: Only the poll creator can close polls").build()).queue(msg -> msg.delete().queueAfter(10, TimeUnit.SECONDS));
return;
}
polls.remove(message.getGuild());
channel.sendMessage(getParsedPoll(poll, message.getGuild()).build()).queue();
message.getTextChannel().sendMessage(EmbedUtil.success("Closed", "Poll was closed by " + message.getAuthor().getAsMention()).build()).queue(msg -> msg.delete().queueAfter(10, TimeUnit.SECONDS));
try {
poll.pollmsgs.forEach((m, c) -> {
Message pollmsg = message.getGuild().getTextChannelById(c).getMessageById(m).complete();
pollmsg.editMessage(getParsedPoll(poll, message.getGuild()).build()).queue();
});
} catch (ErrorResponseException e) {
//This is an empty Catch Block
}
try {
poll.getPollMessages(parsedCommandInvocation.getMessage().getGuild()).forEach(m -> {
m.delete().queue();
});
} catch (Exception ignored) {
}
File file = new File("data/votes/" + message.getGuild().getId() + ".dat");
if(file.exists())
file.delete();
}
示例6: executeWebHook
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
@Override
public boolean executeWebHook(WebHook webHook, WebHookMessage message, Consumer<WebHook> onAbsent) {
if (message == null || message.isEmpty()) {
return false;
}
JSONObject obj = message.toJSONObject();
RestAction<JSONObject> action = new RestAction<JSONObject>(jda, Route.Custom.POST_ROUTE.compile(String.format("webhooks/%s/%s", webHook.getHookId(), webHook.getToken())), obj) {
@SuppressWarnings("unchecked")
@Override
protected void handleResponse(Response response, Request request) {
if (response.isOk()) {
request.onSuccess(null);
} else {
request.onFailure(response);
if (response.code == 404) {
onAbsent.accept(webHook);
}
}
}
};
try {
action.queue();
return false;
} catch (ErrorResponseException e) {
LOGGER.error("Can't execute webhook: ", e);
}
return true;
}
示例7: onFailure
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
public void onFailure(Response response)
{
if (response.code == 429)
{
onFailure(new RateLimitedException(route, response.retryAfter));
}
else
{
onFailure(ErrorResponseException.create(
ErrorResponse.fromJSON(response.getObject()), response));
}
}
示例8: initBotHooks
import net.dv8tion.jda.core.exceptions.ErrorResponseException; //导入依赖的package包/类
public static void initBotHooks(JDAImpl jda)
{
for (Guild guild : jda.getGuilds())
{
if (!guild.getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS))
continue;
RestAction<JSONArray> action = new RestAction<JSONArray>(jda, Route.Custom.GET_ROUTE.compile("guilds/" + guild.getId() + "/webhooks"), null)
{
@SuppressWarnings("unchecked")
@Override
protected void handleResponse(Response response, Request request)
{
if (response.isOk())
{
request.onSuccess(response.getArray());
}
else
{
request.onFailure(response);
}
}
};
try
{
JSONArray hooks = action.block();
for (Object obj : hooks)
{
JSONObject hook = (JSONObject) obj;
JSONObject user = hook.getJSONObject("user");
String channelId = hook.getString("channel_id");
String id = hook.getString("id");
String token = hook.getString("token");
TextChannel channel = jda.getTextChannelById(channelId);
if (user.getString("id").equals(jda.getSelfUser().getId()))
{
webhooks.put(channel, new Webhook(channel, id, token));
}
}
}
catch (RateLimitedException | ErrorResponseException e)
{
logger().error("Can't get guild webhooks: ", e);
}
}
}