[英]Discord Bot sends multiple messages but I only want it to send one
My Discord Bot is sending multiple messages but I just want it to send one message.我的 Discord Bot 正在发送多条消息,但我只希望它发送一条消息。
bot.on('message', msg=>{
if(msg.content == "hello"){
msg.channel.send('Hello!');
}
})
Your code makes your bot send Hello!
您的代码使您的机器人发送
Hello!
to every message, including the Hello!
到每一条消息,包括
Hello!
message your bot just sent.您的机器人刚刚发送的消息。 This means your bot will send
Hello!
这意味着您的机器人将发送
Hello!
to a message, receive the Hello!
来个消息,收到
Hello!
message it just sent, send another message, etc.刚刚发送的消息,发送另一条消息,等等。
You probably want to ignore messages that your bot sent, or generally ignore messages from all bots:您可能想要忽略机器人发送的消息,或者通常忽略来自所有机器人的消息:
bot.on('message', msg=>{
// Ignore messages from your bot
if (msg.author.id === bot.user.id) return
// Or ignore messages from all bots
// if (msg.author.bot) return
// rest of your code...
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.