gpt4 book ai didi

javascript - Discord 机器人编辑消息太慢

转载 作者:行者123 更新时间:2023-12-03 07:25:29 25 4
gpt4 key购买 nike

我希望我的 discordbot 发送一条消息,其中包含附件和文本。然后机器人必须编辑此文本几次,但问题是当机器人编辑消息 5 次然后它等待一段时间然后再次编辑 5 次等等。我怎样才能让它不停地编辑消息?

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

最佳答案

Discord 有一个 rate limit of 5 in each request .试图绕过这将被视为 API 滥用(后面的解决方案不是 API 滥用)。

超过此限制将暂停其他请求,直到经过一定的秒数。随着我的研究,我遇到了这个 simple explanation :每台服务器每 5 秒 5 次(如果您不明白我上面说的)。

关于 Discord's Developer guide on rate limits ,它会告诉你:

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).

在不滥用 API 的情况下,一种解决方法是发送消息并删除之前的消息,因为删除消息的限制更高。

另一种解决方法是为您的动画添加中间超时。一个简单的方法如:

function async wait = { require("util").promisify(setTimeout); };
//syntax: await wait(1000); to "pause" for 1 second

您需要调整时间以适应您预期的动画速度,并且不会因速率限制而暂停。

关于javascript - Discord 机器人编辑消息太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55781980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com