当前位置: 首页>>代码示例>>Java>>正文


Java DiscordException类代码示例

本文整理汇总了Java中sx.blah.discord.util.DiscordException的典型用法代码示例。如果您正苦于以下问题:Java DiscordException类的具体用法?Java DiscordException怎么用?Java DiscordException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DiscordException类属于sx.blah.discord.util包,在下文中一共展示了DiscordException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendConnectionErrorMessage

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
    @NotNull String problem = message != null ? message + "\n" : "";
    if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
        problem += "Service unavailable, please try again latter.";
    } else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
        problem += "Acess dennied.";
    } else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        problem += "Not Found";
    } else {
        problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
    }

    new MessageBuilder(client)
            .appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
            .appendContent("\n")
            .appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
            .appendContent(SPACE)
            .appendContent(command, MessageBuilder.Styles.BOLD)
            .appendContent("\n")
            .appendContent(problem, MessageBuilder.Styles.BOLD)
            .withChannel(channel)
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:24,代码来源:EventUtils.java

示例2: run

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
@Override
public void run(String... arg0) throws Exception
{   
    IDiscordClient client;
    ClientBuilder clientBuilder = new ClientBuilder();
    clientBuilder.withToken(token);

    try
    {
        client = clientBuilder.login();
        
        EventDispatcher dispatcher = client.getDispatcher();
        dispatcher.registerListener(new LeaderboardDiscordActions(client, prefix, leaderboardDao, leaderboardColumnDao));
    }
    catch (DiscordException e)
    {
        e.printStackTrace();
        System.exit(0);
    }
}
 
开发者ID:Vyserion,项目名称:lodbot,代码行数:21,代码来源:Bot.java

示例3: showHelpIfPresent

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
public boolean showHelpIfPresent(IDiscordClient client, IChannel channnel, @NotNull CommandLine cmd) throws RateLimitException, DiscordException, MissingPermissionsException {
    if (cmd.hasOption("h") || cmd.hasOption("help") || cmd.hasOption("showHelp")) {
        @NotNull StringWriter writter = new StringWriter(200);
        @NotNull PrintWriter pw = new PrintWriter(writter);
        new HelpFormatter()
                .printHelp(pw, 200,
                        EventManager.MAIN_COMMAND_NAME + "  " + this.mainCommand,
                        this.commandInfo,
                        this.options,
                        3,
                        5,
                        null,
                        true);
        new MessageBuilder(client)
                .withChannel(channnel)
                .withQuote(writter.toString())
                .send();
        return true;
    }
    return false;
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:22,代码来源:Commands.java

示例4: sendHelloWorld

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private void sendHelloWorld(@NotNull MessageReceivedEvent event, boolean isMention, @Nullable String[] to) throws DiscordException, MissingPermissionsException, RateLimitException {
    @NotNull StringBuilder builder = new StringBuilder(40);
    if (isMention) {
        if (to == null) {
            builder.append(event.getMessage().getAuthor().mention())
                    .append(" ")
                    .append("Hello!");
        } else {
            builder.append("Hello");
            for (String str : to) {
                builder.append(" ")
                        .append(str);
            }
            builder.append("!");
        }
    } else {
        builder.append("Hello World!");
    }
    new MessageBuilder(event.getClient())
            .withChannel(event.getMessage().getChannel())
            .withContent(builder.toString())
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:24,代码来源:SimpleCommandHandler.java

示例5: handle

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
@Override
public boolean handle(@NotNull MessageReceivedEvent event, String command, @NotNull String matchedText) throws
        RateLimitException, DiscordException, MissingPermissionsException {

    if (HELLO_COMMAND.mainCommand().equalsIgnoreCase(command)) {
        try {
            CommandLine cmd = HELLO_COMMAND.parse(matchedText);

            if (HELLO_COMMAND.showHelpIfPresent(event.getClient(), event.getMessage().getChannel(), cmd)) {
                return true;
            }

            boolean isMention = cmd.hasOption("m");
            String[] to = cmd.getOptionValues("m");

            sendHelloWorld(event, isMention, to);

        } catch (ParseException e) {
            logger.info("Parsing failed", e);
            EventUtils.sendIncorrectUsageMessage(event.getClient(), event.getMessage().getChannel(), HELLO_COMMAND.mainCommand(), e.getMessage());
        }
        return true;
    }
    return false;
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:26,代码来源:SimpleCommandHandler.java

示例6: handle

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
/**
 * Called when the event is sent.
 *
 * @param event The event object.
 */
@Override
public void handle(@NotNull final MessageReceivedEvent event) {
    if (!isPingCommand(event)) {
        return;
    }
    logger.traceEntry("Received ping command.");

    try {
        MessageUtils.getDefaultRequestBuilder(event.getMessage())
                    .doAction(Actions.ofSuccess(() -> MessageUtils.getMessageBuilder(event.getMessage())
                        .appendContent("Pong!")
                        .appendContent(System.lineSeparator())
                        .appendContent("Last reponse time in: ")
                        .appendContent(TimeUtils.formatToString(event.getMessage().getShard().getResponseTime(), TimeUnit.MILLISECONDS))
                        .send()))
                    .andThen(Actions.ofSuccess(event.getMessage()::delete))
                    .execute();

    } catch (@NotNull RateLimitException | MissingPermissionsException | DiscordException e) {
        logger.error(e);
    }
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:28,代码来源:PingCommand.java

示例7: moduleLeaveGuild

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private void moduleLeaveGuild(String[] args, MessageReceivedEvent event) {
	if (args.length == 2) {
		if (Main.client.getGuildByID(Long.valueOf(args[1])) != null) {
			RequestBuffer.request(() -> {
				try {
					Main.client.getGuildByID(Long.valueOf(args[1])).leave();
				} catch (DiscordException e) {
					ExceptionHandler.sendException(event.getMessage().getAuthor(), "Failed to leave guild", e, this.getClass());
				}
			});
			Message.sendMessage("Left Guild!", event);
		} else {
			Message.sendMessage("Guild not found!", event);
		}
	} else {
		Message.sendMessage("Please specify the ID of the guild to leave with `!dev leave <ID>`", event);
	}
}
 
开发者ID:NovaFox161,项目名称:DisCal-Discord-Bot,代码行数:19,代码来源:DevCommand.java

示例8: loginBot

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private ResponseEntity<Void> loginBot(@PathVariable String id) {
    BotDTO bot = botService.findOne(id);
    if (bot == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } else {
        try {
            botService.login(bot);
            return ResponseEntity.ok()
                .headers(HeaderUtil.createAlert("Request to login bot " + bot.getId() + " sent", bot.getId()))
                .build();
        } catch (DiscordException e) {
            log.warn("Could not login bot: {}", bot, e);
            return ResponseEntity.badRequest()
                .headers(HeaderUtil.createAlert("Could not login bot: " + e.getErrorMessage(),
                    bot.getId()))
                .body(null);
        }
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:20,代码来源:BotResource.java

示例9: logoutBot

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private ResponseEntity<Void> logoutBot(@PathVariable String id) {
    BotDTO bot = botService.findOne(id);
    if (bot == null) {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    } else {
        try {
            botService.logout(bot);
            return ResponseEntity.ok()
                .headers(HeaderUtil.createAlert("Request to logout bot " + bot.getId() + " sent", bot.getId()))
                .build();
        } catch (DiscordException e) {
            log.warn("Could not logout bot: {}", bot, e);
            return ResponseEntity.badRequest()
                .headers(HeaderUtil.createErrorAlert("Could not logout bot: " + e.getErrorMessage(),
                    bot.getId()))
                .body(null);
        }
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:20,代码来源:BotResource.java

示例10: logout

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private IDiscordClient logout(Bot bot) throws DiscordException {
    log.debug("Request to logout: {}", bot);
    if (!clientRegistry.getClients().containsKey(bot)) {
        throw new IllegalStateException("Bot is not logged in");
    }

    IDiscordClient client = clientRegistry.getClients().get(bot);
    if (client != null) {
        if (client.isLoggedIn()) {
            client.logout();
        } else {
            log.warn("Bot {} is not logged in", bot.getName());
        }
        clientRegistry.getClients().remove(bot);
        commandRegistry.remove(client);
    }

    return client;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:20,代码来源:BotService.java

示例11: sendMessage

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
/**
 * Send a Message in Channel
 * @param channel Channel
 * @param message Message
 * @param delete deletion after time
 */
public static IMessage sendMessage(IChannel channel, String message, boolean delete){
    RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
        try{
            if (channel.getModifiedPermissions(INIT.BOT.getOurUser()).contains(Permissions.SEND_MESSAGES)) {
                IMessage messageinst = channel.sendMessage(message);
                deleteMessageFromBot(messageinst, delete);
                return messageinst;
            } else {
                Console.error(String.format(LANG.getTranslation("notsendpermission_error"), channel.getGuild().getName(), channel.getName()));
                return null;
            }
        } catch (DiscordException e){
            Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
            return null;
        }
    });
    return feature.get();
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:25,代码来源:BotUtils.java

示例12: sendEmbMessage

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
/**
 * Send a Message in Channel
 * @param channel Channel
 * @param builder Message as Embeded Builder Instance
 * @param delete deletion after time
 */
public static IMessage sendEmbMessage(IChannel channel, EmbedBuilder builder, boolean delete){
    RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
        try{
            if (channel.getModifiedPermissions(INIT.BOT.getOurUser()).contains(Permissions.SEND_MESSAGES)) {
                Footer.addFooter(builder);
                IMessage message = channel.sendMessage(builder.build());
                deleteMessageFromBot(message, delete);
                return message;
            } else {
                Console.error(String.format(LANG.getTranslation("notsendpermission_error"), channel.getGuild().getName(), channel.getName()));
                return null;
            }
        } catch (DiscordException e){
            Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
            return null;
        }
    });
    return feature.get();
}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:26,代码来源:BotUtils.java

示例13: sendPrivEmbMessage

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
/**
 * Send a Message in Channel
 * @param channel Channel
 * @param builder Message as Embeded Builder Instance
 */
public static IMessage sendPrivEmbMessage(IPrivateChannel channel, EmbedBuilder builder, boolean delete){
    RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
        try{
            Footer.addFooter(builder);
            IMessage message = channel.sendMessage(builder.build());
            deleteMessageFromBot(message, delete);
            return message;
        } catch (DiscordException e){
            Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
            return null;
        }
    });
    return feature.get();

}
 
开发者ID:ModdyLP,项目名称:MoMuOSB,代码行数:21,代码来源:BotUtils.java

示例14: invokeMethod

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
/**
 * Invokes the method of the command.
 *
 * @param command The command.
 * @param event The event.
 * @param parameters The parameters for the method.
 */
private void invokeMethod(SimpleCommand command, MessageReceivedEvent event, Object[] parameters) {
    Method method = command.getMethod();
    Object reply = null;
    try {
        method.setAccessible(true);
        reply = method.invoke(command.getExecutor(), parameters);
    } catch (IllegalAccessException | InvocationTargetException e) {
        Discord4J.LOGGER.warn("Cannot invoke method {}!", method.getName(), e);
    }
    if (reply != null) {
        try {
            event.getMessage().getChannel().sendMessage(String.valueOf(reply));
        } catch (MissingPermissionsException | RateLimitException | DiscordException ignored) { }
    }
}
 
开发者ID:BtoBastian,项目名称:sdcf4j,代码行数:23,代码来源:Discord4JHandler.java

示例15: commonReply

import sx.blah.discord.util.DiscordException; //导入依赖的package包/类
private CompletableFuture<IMessage> commonReply(IMessage message, Command command, String response, File file) throws InterruptedException, DiscordException, MissingPermissionsException {
    ReplyMode replyMode = command.getReplyMode();
    if (replyMode == ReplyMode.PRIVATE) {
        // always to private - so ignore all permission calculations
        return answerPrivately(message, response, file);
    } else if (replyMode == ReplyMode.ORIGIN) {
        // use the same channel as invocation
        return answer(message, response, command.isMention(), file);
    } else if (replyMode == ReplyMode.PERMISSION_BASED) {
        // the channel must have the needed permission, otherwise fallback to a private message
        if (permissionService.canDisplayResult(command, message.getChannel())) {
            return answer(message, response, command.isMention(), file);
        } else {
            return answerPrivately(message, response, file);
        }
    } else {
        log.warn("This command ({}) has an invalid reply-mode: {}", command.getKey(), command.getReplyMode());
        return answerPrivately(message, response, null);
    }
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:21,代码来源:CommandService.java


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