當前位置: 首頁>>代碼示例>>Java>>正文


Java JDABuilder類代碼示例

本文整理匯總了Java中net.dv8tion.jda.core.JDABuilder的典型用法代碼示例。如果您正苦於以下問題:Java JDABuilder類的具體用法?Java JDABuilder怎麽用?Java JDABuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JDABuilder類屬於net.dv8tion.jda.core包,在下文中一共展示了JDABuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public static void main(String[] args) {
	try{
		new Database();
		OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS);
		JDA jda = new JDABuilder(AccountType.BOT).setToken(Tokens.TOKEN).setHttpClientBuilder(httpBuilder).buildBlocking();
		jda.setAutoReconnect(true);
		jda.addEventListener(new EventHandler(jda));
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
 
開發者ID:Implosions,項目名稱:BullyBot,代碼行數:12,代碼來源:Bot.java

示例2: main

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
    //Code by ZekroTJA(github.com/ZekroTJA)
    StartArgumentHandler.args = args;
    //MY CODE
    builder = new JDABuilder(AccountType.BOT)
            .setToken(SECRETS.TOKEN)
            .setAudioEnabled(true)
            .setAutoReconnect(true)
            .setStatus(STATICS.STATUS)
            .setGame(Game.of(STATICS.CUSTOM_MESSAGE + " | _help | coded by Lee", "http://twitch.tv/lordleeyt"))
            ;

    initializeListeners();
    initializeCommands();
    SQL.connect();
    LVL.connect();


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

}
 
開發者ID:LeeDJD,項目名稱:Amme,代碼行數:26,代碼來源:Main.java

示例3: start

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public void start() throws RateLimitedException, InterruptedException, LoginException {
    this.discordAPI = new JDABuilder(AccountType.BOT)
                              .setToken(settings.getToken())
                              .setGame(new GameImpl(settings.getGame(), settings.getGameUrl(), settings.isTwitch() ? Game.GameType.TWITCH : Game.GameType.DEFAULT))
                              .addListener(new EventCaller(this))
                              .setAutoReconnect(true)
                              .setAudioEnabled(true)
                              .setBulkDeleteSplittingEnabled(false)
                              .buildBlocking();
    if (settings.getRedis().isEnabled()) {
        redisConnection.start();
        keepDataThread.start();
    }
    initCommands();
    initListeners();
}
 
開發者ID:kacperduras,項目名稱:Charrizard,代碼行數:17,代碼來源:Charrizard.java

示例4: initDiscord

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
private static void initDiscord() {
	JDABuilder builder = new JDABuilder(AccountType.BOT);
	try {
		builder.setToken(BotConfig.DISCORD_TOKEN);
		builder.setAutoReconnect(true);
		builder.setStatus(OnlineStatus.ONLINE);
		builder.addEventListener(new ReadyListener());
		builder.addEventListener(new MessageListener());

		builder.buildBlocking();
	} catch (Throwable e) {
		e.printStackTrace();
	} finally {
		builder.setStatus(OnlineStatus.OFFLINE);
	}
}
 
開發者ID:BlackCraze,項目名稱:GameResourceBot,代碼行數:17,代碼來源:Main.java

示例5: setup

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
/**
 * Setup this bot.
 */
private void setup() {
    if (Configs.getMainConfig().getDiscordToken() == null) {
        Core.warn("Discord Token is not set, discord integrations will not function.");
        return;
    }

    try {
        bot = new JDABuilder(AccountType.BOT).setToken(Configs.getMainConfig().getDiscordToken())
                .addEventListener(this).setAutoReconnect(true).setGame(Game.of("Kineticraft"))
                .setStatus(OnlineStatus.ONLINE).buildAsync(); // Setup listener and connect to discord.
        active = true;
    } catch (Exception e) {
        e.printStackTrace();
        Core.warn("Failed to setup discord bot.");
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:20,代碼來源:DiscordBot.java

示例6: start

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public void start() throws LoginException, InterruptedException, RateLimitedException {
    running = true;

    // init logger
    AnsiConsole.systemInstall();
    log = Logger.getLogger("Kyoko");
    log.setUseParentHandlers(false);
    ColoredFormatter formatter = new ColoredFormatter();
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(formatter);
    log.addHandler(handler);

    log.info("Kyoko v" + Constants.VERSION + " is starting...");

    i18n.loadMessages();

    JDABuilder builder = new JDABuilder(AccountType.BOT);
    if (settings.getToken() != null) {
        if (settings.getToken().equalsIgnoreCase("Change me")) {
            System.out.println("No token specified, please set it in config.json");
            System.exit(1);
        }
        builder.setToken(settings.getToken());
    }

    boolean gameEnabled = false;
    if (settings.getGame() != null && !settings.getGame().isEmpty()) {
        gameEnabled = true;
        builder.setGame(Game.of("booting..."));
    }

    builder.setAutoReconnect(true);
    builder.setBulkDeleteSplittingEnabled(false);
    builder.addEventListener(eventHandler);
    builder.setAudioEnabled(true);
    builder.setStatus(OnlineStatus.IDLE);
    jda = builder.buildBlocking();

    log.info("Invite link: " + "https://discordapp.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&scope=bot&permissions=" + Constants.PERMISSIONS);

    if (gameEnabled) {
        Thread t = new Thread(new Kyoko.BlinkThread());
        t.start();
    }

    registerCommands();
}
 
開發者ID:gabixdev,項目名稱:Kyoko,代碼行數:48,代碼來源:Kyoko.java

示例7: loadDiscord

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
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();
	}
}
 
開發者ID:LXGaming,項目名稱:DiscordBot,代碼行數:22,代碼來源:Discord.java

示例8: postInit

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
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();
	}
}
 
開發者ID:LXGaming,項目名稱:DiscordBot,代碼行數:27,代碼來源:DiscordBotCore.java

示例9: initJda

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
/**
 * Starts JDA.
 *
 * @return {@code true} if everything went well, {@code false} otherwise.
 */
private boolean initJda() {

    try {
        SimpleLog.Level level = JDAImpl.LOG.getLevel();
        SimpleLog.Level socketLevel = WebSocketClient.LOG.getLevel();
        JDAImpl.LOG.setLevel(SimpleLog.Level.OFF);
        WebSocketClient.LOG.setLevel(SimpleLog.Level.OFF);

        jda = new JDABuilder(AccountType.BOT).setToken(botToken).buildBlocking();
        jda.getPresence().setGame(Game.of("2.0.2"));
        logger.writeFrom("jda", "Successfully connected!");
        logger.writeFrom("jda WebSocket", "Connected to WebSocket!");

        JDAImpl.LOG.setLevel(level);
        WebSocketClient.LOG.setLevel(socketLevel);
    } catch (LoginException | InterruptedException | RateLimitedException e) {
        logger.writeFrom("jda", "Couldn't connect!");
        e.printStackTrace();
        return false;
    }
    return true;
}
 
開發者ID:iSach,項目名稱:Samaritan,代碼行數:28,代碼來源:Samaritan.java

示例10: SelfBot

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public SelfBot() {
    config = new LoadingProperties();
    clientID = config.getClientID();
    prefix = config.getPrefix();
    pwd = config.getPwd();
    try {
        jda = new JDABuilder(AccountType.CLIENT).setToken(config.getToken()).buildBlocking();
        jda.addEventListener(new CommandListener());
        jda.getPresence().setGame(Game.of(config.getActivity()));
        System.out.println("\nSelfbot ready !");
    } catch (InterruptedException | LoginException | RateLimitedException e) {
        System.out.println("No internet connection or invalid or missing token. Please edit config.blue and try again.");
    }

    //Commands
    commands.put("lenny", new LennyCommand());
    commands.put("game", new GameCommand());
    commands.put("avatars", new AvatarCommand());
    commands.put("ascii", new AsciiCommand());
    commands.put("info", new InfoCommand());
    commands.put("whois", new WhoisCommand());
    commands.put("poll", new PollCommand());
    commands.put("server", new ServerCommand());
    commands.put("idgf", new IdgfCommand());
    commands.put("binary", new BinaryCommand());
    commands.put("reverse", new ReverseCommand());
}
 
開發者ID:thibautbessone,項目名稱:DiscordSelfBlueBot,代碼行數:28,代碼來源:SelfBot.java

示例11: registerEventListeners

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public void registerEventListeners(JDABuilder jda) {
    if (!classLoader.getPlugin().getEventListeners().isEmpty()) {
        for (ListenerAdapter adapter : classLoader.getPlugin().getEventListeners()) {
            jda.addEventListener(adapter);
        }
    }
}
 
開發者ID:avaire,項目名稱:avaire,代碼行數:8,代碼來源:PluginLoader.java

示例12: main

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public static final void main(String[] args) {
    try {
        Standard.setStarted(Instant.now());
        System.setOut(new SystemOutputStream(System.out, false));
        System.setErr(new SystemOutputStream(System.err, true));
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            //Standard.STANDARD_SETTINGS.saveSettings(); //FIXME WTF This is deleting the settings file all the time?!
            Standard.saveAllGuildSettings();
        }));
        Standard.JDA_SUPPLIER = () -> jda;
        NetworkUtil.init();
        reload();
        MySQL.init();
        builder = new JDABuilder(AccountType.BOT);
        builder.setAutoReconnect(true);
        //builder.setAudioSendFactory(null);
        builder.setStatus(OnlineStatus.ONLINE);
        builder.setGame(game = Game.of("Supreme-Bot"));
        initListeners();
        initCommands();
        init();
        initPlugins();
        loadAllGuilds();
        startJDA();
    } catch (Exception ex) {
        System.err.println("Main Error: " + ex);
        ex.printStackTrace();
    }
}
 
開發者ID:Panzer1119,項目名稱:Supreme-Bot,代碼行數:30,代碼來源:SupremeBot.java

示例13: restartJDA

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
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)
		.setAutoReconnect(true)
		.setCorePoolSize(15)
		.setGame(Game.of("Hold on to your seatbelts!"));
	if (totalShards > 1)
		jdaBuilder.useSharding(shardId, totalShards);

	jda = jdaBuilder.buildBlocking();
	readdListeners();
}
 
開發者ID:Mantaro,項目名稱:MantaroRPG,代碼行數:21,代碼來源:MantaroShard.java

示例14: initJDA

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
/**
     * Initializes the JDA instance.
     */
    public static void initJDA() {
        if (instance == null)
            throw new NullPointerException("RubiconBot has not been initialized yet.");

        JDABuilder builder = new JDABuilder(AccountType.BOT);
        builder.setToken(instance.configuration.getString("token"));
        builder.setGame(Game.playing("Starting...."));

        // add all EventListeners
        for (EventListener listener : instance.eventListeners)
            builder.addEventListener(listener);

        new ListenerManager(builder);

        try {
            instance.jda = builder.buildBlocking();
        } catch (LoginException | InterruptedException e) {
            Logger.error(e.getMessage());
        }
        CommandVote.loadPolls(instance.jda);
        Info.lastRestart = new Date();
//      CommandGiveaway.startGiveawayManager(instance.jda);

        getJDA().getPresence().setGame(Game.playing("Started."));
        GameAnimator.start();
    }
 
開發者ID:Rubicon-Bot,項目名稱:Rubicon,代碼行數:30,代碼來源:RubiconBot.java

示例15: ShardingManager

import net.dv8tion.jda.core.JDABuilder; //導入依賴的package包/類
public ShardingManager(int numShards, boolean supportScript) throws Exception {
    Config config = Config.getInstance();
    shards = new JDA[numShards];
    Bot bot = null;
    CommandClient client = null;

    if (!supportScript) {
        bot = new Bot(new EventWaiter());
        CommandClientBuilder commandClientBuilder = new CommandClientBuilder();
        commandClientBuilder.setPrefix("~");
        commandClientBuilder.setOwnerId(config.getConfig(Config.OWNER_ID));

        commandClientBuilder.addCommands(new TestCommand(),
                new PlayCommand(bot),
                new PauseCommand(),
                new RepeatCommand(),
                new StopCommand(),
                new ResumeCommand(),
                new ListTracksCommand());

        commandClientBuilder.setEmojis("\u2714", "\u2757", "\u274c");
        client = commandClientBuilder.build();
    }

    for (int i = 0; i < numShards; i++){
        shards[i] = new JDABuilder(AccountType.BOT)
                .setToken(config.getConfig(Config.DISCORD_TOKEN))
                .useSharding(i, numShards)
                .buildBlocking();
        if (!supportScript) {
            EventWaiter waiter = new EventWaiter();

            shards[i].addEventListener(waiter);
            shards[i].addEventListener(client);
            shards[i].addEventListener(bot);
        }

        System.out.println("Shard " + i + " built.");
    }
}
 
開發者ID:JessWalters,項目名稱:Vinny-Redux,代碼行數:41,代碼來源:ShardingManager.java


注:本文中的net.dv8tion.jda.core.JDABuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。