[Bug]: Rate limits due to patching commands
Senexis opened this issue Β· comments
What happened?
After updating to Discord.js 13.7, patching slash commands will start throwing rateLimit
events. Looking at the requests made, it seems you are using the singular PATCH endpoint instead of the probably intended PUT endpoint (docs here). I don't know if the change happened with something in Discord.js or if Discord themselves started rate limiting the endpoint.
Discord.js does queue and retry the rate limited endpoints as soon as the timeout is over, so it does resolve itself, though if possible it would be preferred to use the proper batch endpoints anyway to save on requests.
In general I would consider the entirety of this logic to be flawed, as I didn't make changes to my commands in the first place and it still tries to PATCH them, but that would be another issue.
Reproduction
- Have a bunch of commands (I have 34).
- Have a listener for the
rateLimit
event:
@Discord()
export abstract class ShardDisconnect {
@On('rateLimit')
shardDisconnect([rateLimitData]: ArgsOf<'rateLimit'>) {
console.log(`Rate limit exceeded.`, { event: rateLimitData });
}
}
- Launch the bot.
- The
/applications/:id/commands/:id
route will be repeatedly called, causing multiplerateLimit
s.
Package
discordx
Version
Stable
Relevant log output
warn: β Rate limit exceeded.
warn: β [ 1] {
warn: β [ 2] event: {
warn: β [ 3] timeout: 19748,
warn: β [ 4] limit: 5,
warn: β [ 5] method: 'patch',
warn: β [ 6] path: '/applications/<snip>/commands/<snip>',
warn: β [ 7] route: '/applications/:id/commands/:id',
warn: β [ 8] global: false
warn: β [ 9] }
warn: β [10] }
Code of Conduct
- I agree to follow this project's Code of Conduct
check logs, turn of silent mode
Turns out it's continuously updating the same commands now, which in itself seems like another bug? I'm not doing anything different and it was skipping commands properly before. Here's the commands output:
[name] >> commands >> guild: #[name]
>> adding 0 []
>> updating 1 [developer]
>> deleting 0 []
>> skipping 0 []
[name] >> commands >> global
>> adding 0 []
>> updating 34 [...]
>> deleting 0 []
>> skipping 0 []
Doesn't seem like I'm getting any other output from DX.
ok, I would recommand, do not update your bot. I have finished the updates, and I will address this and release new minor version
resolved in v9.6.0
Not resolved yet, you should still fix the rate limits at some point if possible. The primary issue (using PATCH instead of PUT) is not resolved yet. If you just have a bunch of added or updated commands you will still hit rate limits.
rate limit handled by discord.js internally, if it's overloaded it will end up in error.
I mean yeah, but this causes the updates to take ~20 seconds per 5 commands updated. Just using PUT would cut that down to milliseconds.
I am not sure what do you mean by PUT, since requests are handled by discord.js
Currently in Client.js
you do cmd.command.edit
in a foreach, while you could just use client.application.commands.set
to update everything at once in one request, avoiding rate limits altogether and turning n
amount of requests into 1 request. To do this though you'll have to provide ALL commands instead of just the updated commands, but that doesn't matter anymore since Discord now instantly updates global commands.
oh that's great, can we do that? can you make PR π