Search in sources :

Example 1 with JDABuilder

use of net.dv8tion.jda.core.JDABuilder in project DiscordBot by LXGaming.

the class Discord method loadDiscord.

public void loadDiscord() {
    try {
        jda = new JDABuilder(AccountType.BOT).setToken(DiscordBot.getInstance().getConfig().getToken()).addEventListener(new DiscordListener()).setAudioEnabled(true).setBulkDeleteSplittingEnabled(false).buildAsync();
        AudioSourceManagers.registerRemoteSources(getAudioPlayerManager());
        audioPlayer = getAudioPlayerManager().createPlayer();
        getAudioPlayer().setVolume(DiscordBot.getInstance().getConfig().getDefaultVolume());
        getAudioPlayer().addListener(new AudioListener());
        getDiscordThread().start();
        getCommand().registerCommands();
        LogHelper.info("Successfully loaded Discord.");
    } catch (LoginException | RateLimitedException | RuntimeException ex) {
        LogHelper.error("Exception loading Discord!");
        ex.printStackTrace();
    }
}
Also used : JDABuilder(net.dv8tion.jda.core.JDABuilder) AudioListener(io.github.lxgaming.discordbot.discord.listeners.AudioListener) LoginException(javax.security.auth.login.LoginException) RateLimitedException(net.dv8tion.jda.core.exceptions.RateLimitedException) DiscordListener(io.github.lxgaming.discordbot.discord.listeners.DiscordListener)

Example 2 with JDABuilder

use of net.dv8tion.jda.core.JDABuilder in project DiscordBot by LXGaming.

the class DiscordBotCore method postInit.

public void postInit() {
    String token = getConfiguration().getToken();
    JDABuilder jdaBuilder = null;
    if (token != null && !token.equals("") && !token.equals("null")) {
        jdaBuilder = new JDABuilder(AccountType.BOT).setToken(token);
    }
    token = null;
    if (jdaBuilder == null) {
        getLogger().severe("Cannot start DiscordBot, No Token / Email and Password provided!");
        return;
    }
    try {
        jda = jdaBuilder.addEventListener(new BotListener()).setAudioEnabled(false).setBulkDeleteSplittingEnabled(false).buildAsync();
    } catch (IllegalArgumentException | LoginException | RateLimitedException ex) {
        getLogger().severe("Connection Failed! Invalid BotToken");
        ex.printStackTrace();
    }
}
Also used : JDABuilder(net.dv8tion.jda.core.JDABuilder) LoginException(javax.security.auth.login.LoginException) BotListener(io.github.lxgaming.discordbot.listeners.BotListener) RateLimitedException(net.dv8tion.jda.core.exceptions.RateLimitedException)

Example 3 with JDABuilder

use of net.dv8tion.jda.core.JDABuilder in project MantaroBot by Mantaro.

the class MantaroShard method restartJDA.

public void restartJDA(boolean force) throws RateLimitedException, LoginException, InterruptedException {
    if (jda != null) {
        log.info("Attempting to drop shard #" + shardId);
        if (!force)
            prepareShutdown();
        jda.shutdown(false);
        log.info("Dropped shard #" + shardId);
    }
    JDABuilder jdaBuilder = new JDABuilder(AccountType.BOT).setToken(config().get().token).setEventManager(manager).setAudioSendFactory(new NativeAudioSendFactory()).setAutoReconnect(true).setCorePoolSize(10).setGame(Game.of("Hold on to your seatbelts!"));
    if (totalShards > 1)
        jdaBuilder.useSharding(shardId, totalShards);
    jda = jdaBuilder.buildBlocking();
    readdListeners();
}
Also used : JDABuilder(net.dv8tion.jda.core.JDABuilder) NativeAudioSendFactory(com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory)

Aggregations

JDABuilder (net.dv8tion.jda.core.JDABuilder)3 LoginException (javax.security.auth.login.LoginException)2 RateLimitedException (net.dv8tion.jda.core.exceptions.RateLimitedException)2 NativeAudioSendFactory (com.sedmelluq.discord.lavaplayer.jdaudp.NativeAudioSendFactory)1 AudioListener (io.github.lxgaming.discordbot.discord.listeners.AudioListener)1 DiscordListener (io.github.lxgaming.discordbot.discord.listeners.DiscordListener)1 BotListener (io.github.lxgaming.discordbot.listeners.BotListener)1