Discord bot editing messages too slow

痞子三分冷 提交于 2021-02-04 20:50:26

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/55781980/discord-bot-editing-messages-too-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!