net.dv8tion.jda.api.requests.GatewayIntent Java Examples

The following examples show how to use net.dv8tion.jda.api.requests.GatewayIntent. 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: AudioEchoExample.java    From JDA with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws LoginException
{
    if (args.length == 0)
    {
        System.err.println("Unable to start without token!");
        System.exit(1);
    }
    String token = args[0];

    // We only need 2 gateway intents enabled for this example:
    EnumSet<GatewayIntent> intents = EnumSet.of(
        // We need messages in guilds to accept commands from users
        GatewayIntent.GUILD_MESSAGES,
        // We need voice states to connect to the voice channel
        GatewayIntent.GUILD_VOICE_STATES
    );

    // Start the JDA session with light mode (minimal cache)
    JDABuilder.createLight(token, intents)           // Use provided token from command line arguments
         .addEventListeners(new AudioEchoExample())  // Start listening with this listener
         .setActivity(Activity.listening("to jams")) // Inform users that we are jammin' it out
         .setStatus(OnlineStatus.DO_NOT_DISTURB)     // Please don't disturb us while we're jammin'
         .enableCache(CacheFlag.VOICE_STATE)         // Enable the VOICE_STATE cache to find a user's connected voice channel
         .build();                                   // Login with these options
}
 
Example #2
Source File: ShardManager.java    From JDA with Apache License 2.0 6 votes vote down vote up
/**
 * Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id.
 * <br>This first calls {@link #getUserById(long)}, and if the return is {@code null} then a request
 * is made to the Discord servers.
 *
 * <p>The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors:
 * <ul>
 *     <li>{@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER ErrorResponse.UNKNOWN_USER}
 *     <br>Occurs when the provided id does not refer to a {@link net.dv8tion.jda.api.entities.User User}
 *     known by Discord. Typically occurs when developers provide an incomplete id (cut short).</li>
 * </ul>
 *
 * @param  id
 *         The id of the requested {@link net.dv8tion.jda.api.entities.User User}.
 *
 * @throws java.lang.IllegalStateException
 *         If there isn't any active shards.
 *
 * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User}
 *         <br>On request, gets the User with id matching provided id from Discord.
 */
@Nonnull
@CheckReturnValue
default RestAction<User> retrieveUserById(long id)
{
    JDA api = null;
    for (JDA shard : getShardCache())
    {
        api = shard;
        EnumSet<GatewayIntent> intents = shard.getGatewayIntents();
        User user = shard.getUserById(id);
        boolean isUpdated = intents.contains(GatewayIntent.GUILD_PRESENCES) || intents.contains(GatewayIntent.GUILD_MEMBERS);
        if (user != null && isUpdated)
            return new CompletedRestAction<>(shard, user);
    }

    if (api == null)
        throw new IllegalStateException("no shards active");

    JDAImpl jda = (JDAImpl) api;
    Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id));
    return new RestActionImpl<>(jda, route, (response, request) -> jda.getEntityBuilder().createFakeUser(response.getObject()));
}
 
Example #3
Source File: GuildImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Task<Void> loadMembers(@Nonnull Consumer<Member> callback)
{
    Checks.notNull(callback, "Callback");
    if (!getJDA().isIntent(GatewayIntent.GUILD_MEMBERS))
        throw new IllegalStateException("Cannot use loadMembers without GatewayIntent.GUILD_MEMBERS!");
    if (isLoaded())
    {
        memberCache.forEachUnordered(callback);
        return new GatewayTask<>(CompletableFuture.completedFuture(null), () -> {});
    }

    MemberChunkManager chunkManager = getJDA().getClient().getChunkManager();
    boolean includePresences = getJDA().isIntent(GatewayIntent.GUILD_PRESENCES);
    CompletableFuture<Void> handler = chunkManager.chunkGuild(this, includePresences, (last, list) -> list.forEach(callback));
    return new GatewayTask<>(handler, () -> handler.cancel(false));
}
 
Example #4
Source File: GuildImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public AudioManager getAudioManager()
{
    if (!getJDA().isIntent(GatewayIntent.GUILD_VOICE_STATES))
        throw new IllegalStateException("Cannot use audio features with disabled GUILD_VOICE_STATES intent!");
    final AbstractCacheView<AudioManager> managerMap = getJDA().getAudioManagersView();
    AudioManager mng = managerMap.get(id);
    if (mng == null)
    {
        // No previous manager found -> create one
        try (UnlockHook hook = managerMap.writeLock())
        {
            GuildImpl cachedGuild = (GuildImpl) getJDA().getGuildById(id);
            if (cachedGuild == null)
                throw new IllegalStateException("Cannot get an AudioManager instance on an uncached Guild");
            mng = managerMap.get(id);
            if (mng == null)
            {
                mng = new AudioManagerImpl(cachedGuild);
                managerMap.getMap().put(id, mng);
            }
        }
    }
    return mng;
}
 
Example #5
Source File: JDAImpl.java    From JDA with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public RestAction<User> retrieveUserById(long id, boolean update)
{
    if (id == getSelfUser().getIdLong())
        return new CompletedRestAction<>(this, getSelfUser());

    AccountTypeException.check(getAccountType(), AccountType.BOT);
    return new DeferredRestAction<>(this, User.class,
            () -> !update || isIntent(GatewayIntent.GUILD_MEMBERS) || isIntent(GatewayIntent.GUILD_PRESENCES) ? getUserById(id) : null,
            () -> {
                Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id));
                return new RestActionImpl<>(this, route,
                        (response, request) -> getEntityBuilder().createFakeUser(response.getObject()));
            });
}
 
Example #6
Source File: GuildImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Task<List<Member>> retrieveMembersByIds(boolean includePresence, @Nonnull long... ids)
{
    Checks.notNull(ids, "ID Array");
    Checks.check(!includePresence || api.isIntent(GatewayIntent.GUILD_PRESENCES),
            "Cannot retrieve presences of members without GUILD_PRESENCES intent!");

    if (ids.length == 0)
        return new GatewayTask<>(CompletableFuture.completedFuture(Collections.emptyList()), () -> {});
    Checks.check(ids.length <= 100, "You can only request 100 members at once");
    MemberChunkManager chunkManager = api.getClient().getChunkManager();
    List<Member> collect = new ArrayList<>(ids.length);
    CompletableFuture<List<Member>> result = new CompletableFuture<>();
    CompletableFuture<Void> handle = chunkManager.chunkGuild(this, includePresence, ids, (last, list) -> {
        collect.addAll(list);
        if (last)
            result.complete(collect);
    });

    result.exceptionally(ex -> {
        WebSocketClient.LOG.error("Encountered exception trying to handle member chunk response", ex);
        return null;
    });

    return new GatewayTask<>(result, () -> handle.cancel(false));
}
 
Example #7
Source File: GuildImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
private Member getMember(long id, boolean update, JDAImpl jda)
{
    if (!update || jda.isIntent(GatewayIntent.GUILD_MEMBERS))
    {
        // return member from cache if member tracking is enabled through intents
        Member member = getMemberById(id);
        // if the join time is inaccurate we also have to load it through REST to update this information
        if (!update || (member != null && member.hasTimeJoined()))
            return member;
    }
    return null;
}
 
Example #8
Source File: GuildImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLoaded()
{
    // Only works with GUILD_MEMBERS intent
    return getJDA().isIntent(GatewayIntent.GUILD_MEMBERS)
            && (long) getMemberCount() <= getMemberCache().size();
}
 
Example #9
Source File: JDAImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public DirectAudioControllerImpl getDirectAudioController()
{
    if (!isIntent(GatewayIntent.GUILD_VOICE_STATES))
        throw new IllegalStateException("Cannot use audio features with disabled GUILD_VOICE_STATES intent!");
    return this.audioController;
}
 
Example #10
Source File: JDAImpl.java    From JDA with Apache License 2.0 5 votes vote down vote up
public boolean chunkGuild(long id)
{
    try
    {
        return isIntent(GatewayIntent.GUILD_MEMBERS) && chunkingFilter.filter(id);
    }
    catch (Exception e)
    {
        LOG.error("Uncaught exception from chunking filter", e);
        return true;
    }
}
 
Example #11
Source File: JDABuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void checkIntents()
{
    boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL)
        throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!");
    else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE)
        JDAImpl.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent.");

    if (!automaticallyDisabled.isEmpty())
    {
        JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents");
        // List each missing intent
        automaticallyDisabled.stream()
            .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")")
            .forEach(JDAImpl.LOG::warn);

        // Tell user how to disable this warning
        JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your JDABuilder",
            automaticallyDisabled.stream()
                .map(it -> "CacheFlag." + it)
                .collect(Collectors.joining(", ")));
        // Only print this warning once
        automaticallyDisabled.clear();
    }

    if (cacheFlags.isEmpty())
        return;

    EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents);
    for (CacheFlag flag : cacheFlags)
    {
        GatewayIntent intent = flag.getRequiredIntent();
        if (intent != null && !providedIntents.contains(intent))
            throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!");
    }
}
 
Example #12
Source File: JDABuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private JDABuilder applyIntents()
{
    EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class);
    for (CacheFlag flag : CacheFlag.values())
    {
        GatewayIntent requiredIntent = flag.getRequiredIntent();
        if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0)
            disabledCache.remove(flag);
    }

    boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE)
            .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT)
            .setDisabledCache(disabledCache);
}
 
Example #13
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void checkIntents()
{
    boolean membersIntent = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    if (!membersIntent && memberCachePolicy == MemberCachePolicy.ALL)
        throw new IllegalStateException("Cannot use MemberCachePolicy.ALL without GatewayIntent.GUILD_MEMBERS enabled!");
    else if (!membersIntent && chunkingFilter != ChunkingFilter.NONE)
        DefaultShardManager.LOG.warn("Member chunking is disabled due to missing GUILD_MEMBERS intent.");

    if (!automaticallyDisabled.isEmpty())
    {
        JDAImpl.LOG.warn("Automatically disabled CacheFlags due to missing intents");
        // List each missing intent
        automaticallyDisabled.stream()
            .map(it -> "Disabled CacheFlag." + it + " (missing GatewayIntent." + it.getRequiredIntent() + ")")
            .forEach(JDAImpl.LOG::warn);

        // Tell user how to disable this warning
        JDAImpl.LOG.warn("You can manually disable these flags to remove this warning by using disableCache({}) on your DefaultShardManagerBuilder",
            automaticallyDisabled.stream()
                    .map(it -> "CacheFlag." + it)
                    .collect(Collectors.joining(", ")));
        // Only print this warning once
        automaticallyDisabled.clear();
    }

    if (cacheFlags.isEmpty())
        return;

    EnumSet<GatewayIntent> providedIntents = GatewayIntent.getIntents(intents);
    for (CacheFlag flag : cacheFlags)
    {
        GatewayIntent intent = flag.getRequiredIntent();
        if (intent != null && !providedIntents.contains(intent))
            throw new IllegalArgumentException("Cannot use CacheFlag." + flag + " without GatewayIntent." + intent + "!");
    }
}
 
Example #14
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 5 votes vote down vote up
private DefaultShardManagerBuilder applyIntents()
{
    EnumSet<CacheFlag> disabledCache = EnumSet.allOf(CacheFlag.class);
    for (CacheFlag flag : CacheFlag.values())
    {
        GatewayIntent requiredIntent = flag.getRequiredIntent();
        if (requiredIntent == null || (requiredIntent.getRawValue() & intents) != 0)
            disabledCache.remove(flag);
    }

    boolean enableMembers = (intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) != 0;
    return setChunkingFilter(enableMembers ? ChunkingFilter.ALL : ChunkingFilter.NONE)
            .setMemberCachePolicy(enableMembers ? MemberCachePolicy.ALL : MemberCachePolicy.DEFAULT)
            .setDisabledCache(disabledCache);
}
 
Example #15
Source File: ShardManager.java    From JDA with Apache License 2.0 5 votes vote down vote up
/**
 * The {@link GatewayIntent GatewayIntents} for the JDA sessions of this shard manager.
 *
 * @return {@link EnumSet} of active gateway intents
 */
@Nonnull
default EnumSet<GatewayIntent> getGatewayIntents()
{
    //noinspection ConstantConditions
    return getShardCache().applyStream((stream) ->
            stream.map(JDA::getGatewayIntents)
                  .findAny()
                  .orElse(EnumSet.noneOf(GatewayIntent.class)));
}
 
Example #16
Source File: SkyBot.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
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 #17
Source File: JDABuilder.java    From JDA with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a new {@link net.dv8tion.jda.api.JDA} instance and uses the provided token to start the login process.
 * <br>The login process runs in a different thread, so while this will return immediately, {@link net.dv8tion.jda.api.JDA} has not
 * finished loading, thus many {@link net.dv8tion.jda.api.JDA} methods have the chance to return incorrect information.
 * For example {@link JDA#getGuilds()} might return an empty list or {@link net.dv8tion.jda.api.JDA#getUserById(long)} might return null
 * for arbitrary user IDs.
 *
 * <p>If you wish to be sure that the {@link net.dv8tion.jda.api.JDA} information is correct, please use
 * {@link net.dv8tion.jda.api.JDA#awaitReady() JDA.awaitReady()} or register an
 * {@link net.dv8tion.jda.api.hooks.EventListener EventListener} to listen for the
 * {@link net.dv8tion.jda.api.events.ReadyEvent ReadyEvent}.
 *
 * @throws LoginException
 *         If the provided token is invalid.
 * @throws IllegalArgumentException
 *         If the provided token is empty or null. Or the provided intents/cache configuration is not possible.
 *
 * @return A {@link net.dv8tion.jda.api.JDA} instance that has started the login process. It is unknown as
 *         to whether or not loading has finished when this returns.
 *
 * @see    net.dv8tion.jda.api.JDA#awaitReady()
 */
@Nonnull
public JDA build() throws LoginException
{
    checkIntents();
    OkHttpClient httpClient = this.httpClient;
    if (httpClient == null)
    {
        if (this.httpClientBuilder == null)
            this.httpClientBuilder = IOUtil.newHttpClientBuilder();
        httpClient = this.httpClientBuilder.build();
    }

    WebSocketFactory wsFactory = this.wsFactory == null ? new WebSocketFactory() : this.wsFactory;

    if (controller == null && shardInfo != null)
        controller = new ConcurrentSessionController();

    AuthorizationConfig authConfig = new AuthorizationConfig(token);
    ThreadingConfig threadingConfig = new ThreadingConfig();
    threadingConfig.setCallbackPool(callbackPool, shutdownCallbackPool);
    threadingConfig.setGatewayPool(mainWsPool, shutdownMainWsPool);
    threadingConfig.setRateLimitPool(rateLimitPool, shutdownRateLimitPool);
    threadingConfig.setEventPool(eventPool, shutdownEventPool);
    SessionConfig sessionConfig = new SessionConfig(controller, httpClient, wsFactory, voiceDispatchInterceptor, flags, maxReconnectDelay, largeThreshold);
    MetaConfig metaConfig = new MetaConfig(maxBufferSize, contextMap, cacheFlags, flags);

    JDAImpl jda = new JDAImpl(authConfig, sessionConfig, threadingConfig, metaConfig);
    jda.setMemberCachePolicy(memberCachePolicy);
    // We can only do member chunking with the GUILD_MEMBERS intent
    if ((intents & GatewayIntent.GUILD_MEMBERS.getRawValue()) == 0)
        jda.setChunkingFilter(ChunkingFilter.NONE);
    else
        jda.setChunkingFilter(chunkingFilter);

    if (eventManager != null)
        jda.setEventManager(eventManager);

    if (audioSendFactory != null)
        jda.setAudioSendFactory(audioSendFactory);

    listeners.forEach(jda::addEventListener);
    jda.setStatus(JDA.Status.INITIALIZED);  //This is already set by JDA internally, but this is to make sure the listeners catch it.

    // Set the presence information before connecting to have the correct information ready when sending IDENTIFY
    ((PresenceImpl) jda.getPresence())
            .setCacheActivity(activity)
            .setCacheIdle(idle)
            .setCacheStatus(status);
    jda.login(shardInfo, compression, true, intents);
    return jda;
}
 
Example #18
Source File: JDAImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
public boolean isIntent(GatewayIntent intent)
{
    int raw = intent.getRawValue();
    return (client.getGatewayIntents() & raw) == raw;
}
 
Example #19
Source File: JDAImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
public int login() throws LoginException
{
    return login(null, null, Compression.ZLIB, true, GatewayIntent.ALL_INTENTS);
}
 
Example #20
Source File: DefaultShardManager.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public EnumSet<GatewayIntent> getGatewayIntents()
{
    return GatewayIntent.getIntents(shardingConfig.getIntents());
}
 
Example #21
Source File: JDAImpl.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public EnumSet<GatewayIntent> getGatewayIntents()
{
    return GatewayIntent.getIntents(client.getGatewayIntents());
}
 
Example #22
Source File: ShardingConfig.java    From JDA with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static ShardingConfig getDefault()
{
    return new ShardingConfig(1, false, GatewayIntent.ALL_INTENTS, MemberCachePolicy.ALL);
}
 
Example #23
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with low memory profile settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setEnabledIntents(Collection)} is set to {@link GatewayIntent#DEFAULT}</li>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#NONE}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>This disables all existing {@link CacheFlag CacheFlags}</li>
 * </ul>
 *
 * @param  token
 *         The bot token to use
 *
 * @return The new DefaultShardManagerBuilder
 *
 * @see    #disableIntents(GatewayIntent, GatewayIntent...)
 * @see    #enableIntents(GatewayIntent, GatewayIntent...)
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createLight(@Nullable String token)
{
    return new DefaultShardManagerBuilder(token, GatewayIntent.DEFAULT).applyLight();
}
 
Example #24
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with low memory profile settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#NONE}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>This disables all existing {@link CacheFlag CacheFlags}</li>
 * </ul>
 *
 * <p>If you don't enable certain intents, the cache will be disabled.
 * For instance, if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled, then members will only
 * be cached when a voice state is available.
 * If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} are disabled
 * then no members will be cached.
 *
 * <p>The individual {@link CacheFlag CacheFlags} will also be disabled
 * if the {@link CacheFlag#getRequiredIntent() required intent} is not enabled.
 *
 * @param  token
 *         The bot token to use
 * @param  intent
 *         The first intent to use
 * @param  intents
 *         The other gateway intents to use
 *
 * @return The new DefaultShardManagerBuilder
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createLight(@Nullable String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
{
    Checks.notNull(intent, "GatewayIntent");
    Checks.noneNull(intents, "GatewayIntent");
    return createLight(token, EnumSet.of(intent, intents));
}
 
Example #25
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with recommended default settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#DEFAULT}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>This disables {@link CacheFlag#ACTIVITY} and {@link CacheFlag#CLIENT_STATUS}</li>
 * </ul>
 *
 * <p>If you don't enable certain intents, the cache will be disabled.
 * For instance, if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled, then members will only
 * be cached when a voice state is available.
 * If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} are disabled
 * then no members will be cached.
 *
 * <p>The individual {@link CacheFlag CacheFlags} will also be disabled
 * if the {@link CacheFlag#getRequiredIntent() required intent} is not enabled.
 *
 * @param  token
 *         The bot token to use
 * @param  intents
 *         The intents to enable
 *
 * @throws IllegalArgumentException
 *         If provided with null intents
 *
 * @return The new DefaultShardManagerBuilder
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createDefault(@Nullable String token, @Nonnull Collection<GatewayIntent> intents)
{
    return create(token, intents).applyDefault();
}
 
Example #26
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with recommended default settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#DEFAULT}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>This disables {@link CacheFlag#ACTIVITY} and {@link CacheFlag#CLIENT_STATUS}</li>
 * </ul>
 *
 * <p>If you don't enable certain intents, the cache will be disabled.
 * For instance, if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled, then members will only
 * be cached when a voice state is available.
 * If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} are disabled
 * then no members will be cached.
 *
 * <p>The individual {@link CacheFlag CacheFlags} will also be disabled
 * if the {@link CacheFlag#getRequiredIntent() required intent} is not enabled.
 *
 * @param  token
 *         The bot token to use
 * @param  intent
 *         The intent to enable
 * @param  intents
 *         Any other intents to enable
 *
 * @throws IllegalArgumentException
 *         If provided with null intents
 *
 * @return The new DefaultShardManagerBuilder
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createDefault(@Nullable String token, @Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
{
    Checks.notNull(intent, "GatewayIntent");
    Checks.noneNull(intents, "GatewayIntent");
    return createDefault(token, EnumSet.of(intent, intents));
}
 
Example #27
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with low memory profile settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#NONE}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>This disables all existing {@link CacheFlag CacheFlags}</li>
 * </ul>
 *
 * <p>If you don't enable certain intents, the cache will be disabled.
 * For instance, if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled, then members will only
 * be cached when a voice state is available.
 * If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} are disabled
 * then no members will be cached.
 *
 * <p>The individual {@link CacheFlag CacheFlags} will also be disabled
 * if the {@link CacheFlag#getRequiredIntent() required intent} is not enabled.
 *
 * @param  token
 *         The bot token to use
 * @param  intents
 *         The gateway intents to use
 *
 * @return The new DefaultShardManagerBuilder
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createLight(@Nullable String token, @Nonnull Collection<GatewayIntent> intents)
{
    return create(token, intents).applyLight();
}
 
Example #28
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a DefaultShardManagerBuilder with recommended default settings.
 * <br>Note that these defaults can potentially change in the future.
 *
 * <ul>
 *     <li>{@link #setMemberCachePolicy(MemberCachePolicy)} is set to {@link MemberCachePolicy#DEFAULT}</li>
 *     <li>{@link #setChunkingFilter(ChunkingFilter)} is set to {@link ChunkingFilter#NONE}</li>
 *     <li>{@link #setEnabledIntents(Collection)} is set to {@link GatewayIntent#DEFAULT}</li>
 *     <li>This disables {@link CacheFlag#ACTIVITY} and {@link CacheFlag#CLIENT_STATUS}</li>
 * </ul>
 *
 * @param  token
 *         The bot token to use
 *
 * @return The new DefaultShardManagerBuilder
 *
 * @see    #disableIntents(GatewayIntent, GatewayIntent...)
 * @see    #enableIntents(GatewayIntent, GatewayIntent...)
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder createDefault(@Nullable String token)
{
    return new DefaultShardManagerBuilder(token, GatewayIntent.DEFAULT).applyDefault();
}
 
Example #29
Source File: DefaultShardManagerBuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a completely empty DefaultShardManagerBuilder with the predefined intents.
 * <br>You can use {@link #create(Collection) DefaultShardManagerBuilder.create(EnumSet.noneOf(GatewayIntent.class))} to disable all intents.
 *
 * <br>If you use this, you need to set the token using
 * {@link #setToken(String) setToken(String)}
 * before calling {@link #build() build()}
 *
 * <p>If you don't enable certain intents, the cache will be disabled.
 * For instance, if the {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intent is disabled, then members will only
 * be cached when a voice state is available.
 * If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_VOICE_STATES GUILD_VOICE_STATES} are disabled
 * then no members will be cached.
 *
 * <p>The individual {@link CacheFlag CacheFlags} will also be disabled
 * if the {@link CacheFlag#getRequiredIntent() required intent} is not enabled.
 *
 * @param intent
 *        The first intent
 * @param intents
 *        The gateway intents to use
 *
 * @throws IllegalArgumentException
 *         If the provided intents are null
 *
 * @return The DefaultShardManagerBuilder instance
 *
 * @see   #setToken(String)
 */
@Nonnull
@CheckReturnValue
public static DefaultShardManagerBuilder create(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
{
    return create(null, intent, intents);
}
 
Example #30
Source File: JDABuilder.java    From JDA with Apache License 2.0 3 votes vote down vote up
/**
 * Configures which events will be disabled.
 * Bots which did not enable presence/member updates in the developer dashboard are required to disable {@link GatewayIntent#GUILD_PRESENCES} and {@link GatewayIntent#GUILD_MEMBERS}!
 *
 * <p>It is not recommended to disable {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} when
 * using {@link MemberCachePolicy#ALL MemberCachePolicy.ALL} as the members cannot be removed from cache by a leave event without this intent.
 *
 * <p>If you disable certain intents you also have to disable related {@link CacheFlag CacheFlags}.
 * This can be achieved using {@link #disableCache(CacheFlag, CacheFlag...)}. The required intents for each
 * flag are documented in the {@link CacheFlag} enum.
 *
 * @param  intent
 *         The first intent to disable
 * @param  intents
 *         Any other intents to disable
 *
 * @throws IllegalArgumentException
 *         If null is provided
 *
 * @return The JDABuilder instance. Useful for chaining.
 *
 * @see    #setMemberCachePolicy(MemberCachePolicy)
 *
 * @since  4.2.0
 */
@Nonnull
public JDABuilder setDisabledIntents(@Nonnull GatewayIntent intent, @Nonnull GatewayIntent... intents)
{
    Checks.notNull(intent, "Intents");
    Checks.noneNull(intents, "Intents");
    return setDisabledIntents(EnumSet.of(intent, intents));
}