Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

javascript - Discord bot editing messages too slow

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()
      }

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...