Discord bot editing messages too slow
Discord has a rate limit of 5 in each request. Trying to bypass this would be considered API abuse (the solutions later is not API abuse).
Exceeding this limit will pause other requests until a certain number of seconds has passed. Along with my research, I came across this simple explanation:
5 anything per 5 seconds per server
(if you did not understand what I said above).
On Discord's Developer guide on rate limits, it tells you this:
There is currently a single exception to the above rule [rate limits] regarding different HTTP methods sharing the same rate limit, and that is for the deletion of messages. Deleting messages falls under a separate, higher rate limit so that bots are able to more quickly delete content from channels (which is useful for moderation bots).
One workaround, without API abusing, would be to send messages, and delete the previous messages since there is a higher limit for deleting messages.
Another workaround would be to add intermediate timeouts to your animation. A simple method such as:
function async wait = { require("util").promisify(setTimeout); };
//syntax: await wait(1000); to "pause" for 1 second
You will need to play around with the timings so it fits your intended animation speed, and without pausing due to the rate limit.
Related videos on Youtube
Stasio
Updated on June 04, 2022Comments
-
Stasio about 2 years
I want my discordbot to send send a message with an attached file in it and a text. Then the bot has to edit this text a couple of times but the problem is that when bot eddits message 5 times then it waits some time and then edits again 5 times etc etc. How can i make it edit messages without stopping?
if(msg.content.includes("letter")){ msg.channel.send("alphabet", { files: ["/Users/48602/Videos/discordbot/aaa.png"]})} if(msg.content === 'alphabet'){ msg.edit("**a**") msg.edit("**b**") msg.edit("**c**") msg.edit("**d**") // Here bot stop for a 2 seconds and i dont know why msg.edit("**e**") msg.edit("**f**") msg.edit("**g**") msg.edit("**h**") msg.edit("**i**") msg.edit("**j**")// Here bot stop for a 2 seconds and i dont know why msg.edit("**k**") msg.edit("**l**") msg.edit("**m**") msg.edit("**n**") msg.edit("**o**") // Here bot stop for a 2 seconds and i dont know why msg.delete() }
-
Anu6is about 5 yearsThat's likely due to Discord Rate Limits, which you cannot circumvent. The rate limits are there to prevent you from spamming the API, which is exactly what you are doing in your example. Note that if you continuously hit the rate limits, your bot account can be banned.
-
Anu6is about 5 yearsAdditionally, why would do what you're doing exactly? Editing the message immediately without any sort of delay means the user barely has a chance (if at all) to see what is actually being sent. What exactly is use case for this type of behavior?
-
Stasio about 5 yearsIts just an example. In my case i want to do smth like game "slots" on casino but when i add like 1s or 2 s delay between those edits the bot will stop after 5 times anyway is there a way to fix it?
-
Stasio about 5 yearsHow long should be delay between edits
-
Anu6is about 5 yearsYou shouldn't be trying try create some sort of animation by continuously editing a message. Just show the final result of the slot rotations. Like I said, there are no ways to get around rate limits outside of simply reducing the frequency of what you're doing. The limits are there for a reason (explained in the link provided)
-
Anu6is about 5 yearsI believe sending/editing messages is something like 5 every 5 seconds. Although with discord that's not necessarily set in stone. The limits are sent with request headers and can be changed on Discord's end
-
-
PLASMA chicken about 5 yearsdiscord.js acutally handles the ratelimits and thats why it sends it in bursts of 5. This is planned behaviour.