![](/img/trans.png)
[英]How do I make discord bot have an emoji reaction after it sends its message in discord.js?
[英]How to make an discord js bot to send an random message(i make an list and he sends it) at some time in an exact text channel from discord
首先,您需要找到頻道 ID。 最好將 go 進入 Discord 應用程序並右鍵單擊通道和 select “復制 ID”。 它應該看起來像這樣:845346073543326453
現在要將某些內容發送到該特定頻道,您必須執行以下操作:
const channel = client.channels.cache.get(845346073543326453);
channel.send("hello!")
對於隨機消息,您只需創建一個數組並隨機選擇一個:
const random = (min, max) => {
return Math.floor(Math.random() * (max - min + 1) + min);
}
let randomMsg = [`Howdy`, `Howdily doodily`, `Zoinks`]
channel.send(quotes[random(0, quotes.length - 1)])
在特定時間發送它有很多方法。 我建議使用cron
package 並參考這篇文章: 如何每天在特定時間發送消息?
但是,如果您只是想要一種快速且非常省力的方式,您可以使用 setInterval() 並將延遲設置為一個小時。 所以我們最終會得到這樣的結果:
const channel = client.channels.cache.get(845346073543326453);
const randomMsg = [`Howdy`, `Howdily doodily`, `Zoinks`]
const random = (min, max) => {
return Math.floor(Math.random() * (max - min + 1) + min);
}
const sendRandomMsg = () => {
var d = new Date();
var n = d.getHours();
if (n === 12) {
channel.send(randomMsg[random(0, quotes.length - 1)])
}
}
setInterval(function(){ sendRandomMsg() }, 3600000);
您可以在 if 中添加更多功能,以防您在特定時間有更多功能要運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.