問題描述
我希望我的 discordbot 發送帶有附件和文本的發送消息.然后機器人必須編輯此文本幾次,但問題是當機器人編輯消息 5 次時,它會等待一段時間,然后再次編輯 5 次等等.我怎樣才能讓它不停地編輯消息?
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()
}
推薦答案
Discord 有一個 每個請求的速率限制為 5.試圖繞過這一點將被視為 API 濫用(后面的解決方案不是 API 濫用).
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).
超過此限制將暫停其他請求,直到經過一定秒數.隨著我的研究,我發現了這個簡單解釋:每臺服務器每 5 秒 5 次
(如果你不明白我上面所說的).
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).
在 Discord 的速率限制開發者指南上,它告訴您:
上述規則[速率限制]目前有一個例外,即不同的 HTTP 方法共享相同的速率限制,即刪除消息.刪除消息屬于單獨的更高速率限制,以便機器人能夠更快地從頻道中刪除內容(這對于審核機器人很有用).
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 的情況下,一種解決方法是發送消息,然后刪除以前的消息,因為刪除消息的限制更高.
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.
這篇關于Discord bot 編輯消息太慢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!