discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.35k stars 735 forks source link

Hit the WebSocket RateLimit! #1290

Closed Andre601 closed 4 years ago

Andre601 commented 4 years ago

General Troubleshooting

Question

When building a ShardManager instance using the DefaultShardManagerBuilder and also disabling specific Intents and CacheFlags do I receive these warnings without knowing what the issue is:

Hit the WebSocket RateLimit! This can be caused by too many presence or voice status updates (connect/disconnect/mute/deaf). Regular: 0 Voice: 0 Chunking: 503

(note that 503 is different depending on the shard)

This starts once the bot connects to the websocket (Connected to WebSocket! message) and then spams in regular intervals the console.

Example Code

Code used to built a ShardManager instance

/*
 * getFileManager() is a getter for a class that loads and handles JSON files.
 * waiter is a EventWaiter (JDA-Utilities) instance.
 * getMessageUtils() is a class for various message-related stuff (in this case getting a random startup message)
 */
DefaultShardManagerBuilder
    .create(
        getFileManager().getString("config", "bot-token"),
        GatewayIntent.GUILD_MEMBERS,
        GatewayIntent.GUILD_MESSAGES,
        GatewayIntent.GUILD_EMOJIS,
        GatewayIntent.GUILD_MESSAGE_REACTIONS
    )
    .disableIntents(
        GatewayIntent.GUILD_VOICE_STATES, 
        GatewayIntent.GUILD_PRESENCES
    )
    .disableCache(
        CacheFlag.ACTIVITY, 
        CacheFlag.VOICE_STATE,
        CacheFlag.CLIENT_STATUS
    )
    .addEventListeners(
        new ReadyListener(this),
        new ConnectionListener(this),
        new GuildListener(this),
        new CommandListener(this, CMD_HANDLER),
        waiter
    )
    .setShardsTotal(-1)
    .setActivity(Activity.of(Activity.ActivityType.DEFAULT, getMessageUtil().getRandomStartupMsg()))
    .setStatus(OnlineStatus.DO_NOT_DISTURB)
    .build();
MinnDevelopment commented 4 years ago

This is intended behavior. Discord requires to chunk the members for each guild individually. You have to either accept these warnings or disable chunking with setChunkingFilter(ChunkingFilter.NONE).

Andre601 commented 4 years ago

Would disabling the ChunkingFilter have any major impact on the bot? Like on what methods you can use or the general performance? Or is it neglectable?

MinnDevelopment commented 4 years ago

Without chunking, JDA will use lazy loading and start off with a minimal set of members. If the GUILD_PRESENCES intent is disabled, we start off with only voice members. With GUILD_PRESENCES we start with online members and voice members. Additional members will be loaded once they are active.

There are many ways to load and access members without chunking:

Andre601 commented 4 years ago

Will Message#getMember() and similar get methods still work?

MinnDevelopment commented 4 years ago

Will Message#getMember() and similar get methods still work?

Depends on the message origin. In events, yes. When you do retrieveMessageById discord currently doesn't provide the member instance, so it will be null.

Andre601 commented 4 years ago

Thanks for the clarifications.