net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder Java Examples
The following examples show how to use
net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder.
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: DiscordServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@PostConstruct public void init() { String token = workerProperties.getDiscord().getToken(); Objects.requireNonNull(token, "No Discord Token specified"); try { RestAction.setPassContext(false); DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder() .setToken(token) .setEventManagerProvider(id -> eventManager) .addEventListeners(this) .setShardsTotal(workerProperties.getDiscord().getShardsTotal()) .setEnableShutdownHook(false); if (audioService != null) { audioService.configure(this, builder); } shardManager = builder.build(); } catch (LoginException e) { log.error("Could not login user with specified token", e); } }
Example #2
Source File: DefaultAudioServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public void configure(DiscordService discordService, DefaultShardManagerBuilder builder) { if (!getConfiguration().isEnabled()) { return; } lavaLink = new JdaLavalink( discordService.getUserId(), workerProperties.getDiscord().getShardsTotal(), discordService::getShardById ); builder.setVoiceDispatchInterceptor(lavaLink.getVoiceInterceptor()); builder.addEventListeners(lavaLink); if (CollectionUtils.isNotEmpty(getConfiguration().getNodes())) { getConfiguration().getNodes().forEach(e -> { try { lavaLink.addNode(e.getName(), new URI(e.getUrl()), e.getPassword()); } catch (URISyntaxException e1) { log.warn("Could not add node {}", e, e1); } }); } var discovery = getConfiguration().getDiscovery(); if (discovery != null && discovery.isEnabled() && StringUtils.isNotEmpty(discovery.getServiceName())) { scheduler.scheduleWithFixedDelay(this::lookUpDiscovery, 60000); } }
Example #3
Source File: BotManager.java From Arraybot with Apache License 2.0 | 5 votes |
/** * Gets the default shard manager. * @return The default shard manager. * @throws LoginException If the bot could not log in. */ private ShardManager createShardManager() throws LoginException { return new DefaultShardManagerBuilder() .setToken(configuration.isBotBeta() ? configuration.getBotBetaToken() : configuration.getBotToken()) .setStatus(OnlineStatus.DO_NOT_DISTURB) .setShardsTotal(configuration.getBotShards()) .addEventListeners(new ReadyListener()) .setUseShutdownNow(true) .setActivity(Activity.listening(configuration.getBotPrefix() + "help || v" + configuration.getBotVersion())) .build(); }
Example #4
Source File: SkyBot.java From SkyBot with GNU Affero General Public License v3.0 | 4 votes |
private SkyBot() throws Exception { // Set our animated emotes as default reactions MessageUtils.setErrorReaction("a:_no:577795484060483584"); MessageUtils.setSuccessReaction("a:_yes:577795293546938369"); // Load in our container final Variables variables = new Variables(); final DunctebotConfig config = variables.getConfig(); final CommandManager commandManager = variables.getCommandManager(); final Logger logger = LoggerFactory.getLogger(SkyBot.class); // Set the user-agent of the bot WebUtils.setUserAgent("Mozilla/5.0 (compatible; SkyBot/" + Settings.VERSION + "; +https://dunctebot.com;)"); EmbedUtils.setEmbedBuilder( () -> new EmbedBuilder() .setColor(Settings.DEFAULT_COLOUR) // .setFooter("DuncteBot", Settings.DEFAULT_ICON) // .setTimestamp(Instant.now()) ); Settings.PREFIX = config.discord.prefix; // Set some defaults for rest-actions RestAction.setPassContext(true); RestAction.setDefaultFailure(ignore(UNKNOWN_MESSAGE)); // If any rest-action doesn't get executed within 2 minutes we will mark it as failed RestAction.setDefaultTimeout(2L, TimeUnit.MINUTES); if (variables.useApi()) { logger.info(TextColor.GREEN + "Using api for all connections" + TextColor.RESET); } else { logger.warn("Using SQLite as the database"); logger.warn("Please note that is is not recommended for production"); } //Load the settings before loading the bot GuildSettingsUtils.loadAllSettings(variables); //Set the token to a string final String token = config.discord.token; //But this time we are going to shard it final int totalShards = config.discord.totalShards; this.activityProvider = (shardId) -> Activity.playing( config.discord.prefix + "help | Shard " + (shardId + 1) ); final LongLongPair commandCount = commandManager.getCommandCount(); logger.info("{} commands with {} aliases loaded.", commandCount.getFirst(), commandCount.getSecond()); LavalinkManager.ins.start(config, variables.getAudioUtils()); final EventManager eventManager = new EventManager(variables); // Build our shard manager final DefaultShardManagerBuilder builder = DefaultShardManagerBuilder.create( GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_BANS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_MESSAGES ) .setToken(token) .setShardsTotal(totalShards) .setActivityProvider(this.activityProvider) .setBulkDeleteSplittingEnabled(false) .setEventManagerProvider((id) -> eventManager) // Keep guild owners, voice members and patrons in cache .setMemberCachePolicy(MemberCachePolicy.DEFAULT.or(PATRON_POLICY)) // .setMemberCachePolicy(MemberCachePolicy.NONE) // Enable lazy loading .setChunkingFilter(ChunkingFilter.NONE) // Enable lazy loading for guilds other than our own // .setChunkingFilter((guildId) -> guildId == Settings.SUPPORT_GUILD_ID) .enableCache(CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.MEMBER_OVERRIDES) .disableCache(CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS) .setHttpClientBuilder( new OkHttpClient.Builder() .connectTimeout(30L, TimeUnit.SECONDS) .readTimeout(30L, TimeUnit.SECONDS) .writeTimeout(30L, TimeUnit.SECONDS) ); this.startGameTimer(); // If lavalink is enabled we will hook it into jda if (LavalinkManager.ins.isEnabled()) { builder.setVoiceDispatchInterceptor(LavalinkManager.ins.getLavalink().getVoiceInterceptor()); } this.shardManager = builder.build(); HelpEmbeds.init(commandManager); // Load the web server if we are not running "locally" // TODO: change this config value to "web_server" or something if (!config.discord.local) { webRouter = new WebRouter(shardManager, variables); } }
Example #5
Source File: AudioService.java From JuniperBot with GNU General Public License v3.0 | votes |
void configure(DiscordService discordService, DefaultShardManagerBuilder builder);