net.dv8tion.jda.core.JDABuilder Java Examples

The following examples show how to use net.dv8tion.jda.core.JDABuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DiscordBotCore.java    From DiscordBot with Apache License 2.0 6 votes vote down vote up
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();
	}
}
 
Example #2
Source File: Main.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {

        StartArgumentHandler.args = args;

        SettingsCore.loadSettings();

        mySql = new MySql(STATICS.SQL_HOST, STATICS.SQL_PORT, STATICS.SQL_USER, STATICS.SQL_PASS, STATICS.SQL_DB).initialize();

        BotStats.load();

        if (!new File("WILDCARDS.txt").exists())
            ServerLimitListener.createTokenList(50);


        File savePath = new File("saves_playlists");
        if (!savePath.exists() || !savePath.isDirectory()) {
            System.out.println(
                    savePath.mkdir() ? "[INFO] Path \"saves_playlists\" successfully created!" : "[ERROR] Failed to create path \"saves_playlists\"!"
            );
        }

        builder = new JDABuilder(AccountType.BOT)
                .setToken(STATICS.TOKEN)
                .setAudioEnabled(true)
                .setAutoReconnect(true)
                .setStatus(STATICS.STATUS)
                .setGame(STATICS.GAME);

        initializeListeners();
        initializeCommands();

        try {
            builder.buildBlocking();
        } catch (InterruptedException | RateLimitedException | LoginException e) {
            e.printStackTrace();
        }

    }
 
Example #3
Source File: Discord.java    From DiscordBot with Apache License 2.0 5 votes vote down vote up
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();
	}
}