• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ErrorResponseException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
    }


}
 
开发者ID:LeeDJD,项目名称:Amme,代码行数:27,代码来源:Vote.java


示例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);
        };
    }
 
开发者ID:napstr,项目名称:wolfia,代码行数:17,代码来源:RestActions.java


示例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);
    }
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:36,代码来源:RestAction.java


示例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());
    });
}
 
开发者ID:jagrosh,项目名称:GiveawayBot,代码行数:29,代码来源:Giveaway.java


示例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();
}
 
开发者ID:Rubicon-Bot,项目名称:Rubicon,代码行数:38,代码来源:CommandVote.java


示例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;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:31,代码来源:DiscordServiceImpl.java


示例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));
    }
}
 
开发者ID:DV8FromTheWorld,项目名称:JDA,代码行数:13,代码来源:Request.java


示例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);
        }
    }
}
 
开发者ID:SalonDesDevs,项目名称:Shenron-Legacy,代码行数:53,代码来源:Webhook.java



注:本文中的net.dv8tion.jda.core.exceptions.ErrorResponseException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HistoryItem类代码示例发布时间:2022-05-22
下一篇:
Java EndpointDetails类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap