简体   繁体   English

Discord Bot 发送多条消息,但我只希望它发送一条

[英]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.

相关问题 我的 Discord 机器人多次响应一个命令,我想知道是否有办法只发送一次 - My Discord bot reponds multiple time to one command and I want to know if there's a way to send it only once 让discord bot只用一个命令发送许多消息 - Have a discord bot send many messages with only one command 我希望机器人只发送随机消息,但一条消息只发送一次 - I want a bot to send random messages only but one message only once 我的 discord.js 机器人发送多个 gif 而不是一个。 我该如何解决? - My discord.js bot sends multiple gifs instead of one. How do I fix this? 我的 Discord 机器人以一种奇怪的方式发送消息 - My Discord bot sends messages in a weird way 一旦discord bot重新连接而不是一个,如何修复发送的多个消息? - How to fix multiple messages being send once a discord bot reconnects instead of one? 我想从多个文本输入中获取输入并将其发送到我的数据库,但是只有最后一个输入发送 - I want to take input from multiple text inputs and send them to my database, but only the last input sends 想让机器人只向特定的人发送消息 - Want to make bot only send messages to a specific person 我只想从一个语音通道控制我的 Discord 机器人 - I want to control my Discord bot only from one voice channel 我的不和谐机器人一次发送多条消息,而不是一条 - My discord bot is sending multiple messages at once instead of just one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM