[英]Discord.js - While loop for a message
我是 JavaScript 的新手,我決定從 discord.js 開始制作我的第一個項目,我試圖將垃圾郵件命令作為挑戰,但這似乎不起作用
client.on('message', msg => {
if (msg.content == 'spam') {
while (true) {
msg.channel.send('@everyone');
}
}
});
沒關系,我修好了,如果你有興趣,我就是這樣做的:
client.on("message", async (msg) => {
if (msg.content === "spam") {
while (true) {
await msg.channel.send("@everyone");
}
}
})
首先你不應該這樣做,你基本上是在濫用 api 並且最終會受到速率限制
其次,你需要等待,記住不要垃圾郵件:D
cleint.on('message', async msg => {
let spam = false;
if (msg.content.toLowerCase() === 'spam') spam = true;
else if (msg.content.toLowerCase() === 'stop spam') spam = false;
while (spam == true)
await msg.channel.send('spamming is bad');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.