【问题标题】:How can I make a discord bot check the contents of a message and reply with a different message depending on the author?如何让不和谐机器人检查消息的内容并根据作者回复不同的消息?
【发布时间】:2021-07-25 12:42:17
【问题描述】:

如何让 Discord 机器人检查消息的内容并根据作者回复不同的消息? 到目前为止,这是我的代码,我在教程中找到了它,但它不起作用。 (由于某种原因没有错误消息)

client.on('message', function (userID, channelID, message) {
    const thisWord = "i'm so cool";
    if(message.content.includes(thisWord)) {
      if(userID === '<@ID>'){
        client.sendMessage({
          to: channelID,
          message: "agreed"
      })
    }}
        else {
          client.sendMessage({
            to: channelID,
            message: "disagreed"
          })
        }
  })

【问题讨论】:

标签: javascript discord.js


【解决方案1】:

首先,您必须使用更高版本的 DJS。请更新到最新的稳定版本 v12.5.3。其次,message 事件仅接受一个参数,而您提供了三个参数。第三,如果你想对不同的消息发送不同的回复,那么你需要对消息内容进行处理。即按空格分割消息内容,然后进行处理。 This 可能会指导您使用用户输入命令。

【讨论】:

    【解决方案2】:

    这里的问题看起来像是您使用的是旧版本的 DJS。使用最新的。

    这将是 discord.js v 12.5.3 的正确用法

    // the id should be like this '429493473259814923' :)
    client.on('message', async message => {
        const thisWord = 'i\'m so cool';
        if (message.content.toLowerCase().includes(thisWord)) {
            if (message.author.id === 'ID') message.reply('disagreed');
            else message.reply('disagreed');
        }
    });
    
    

    【讨论】:

      猜你喜欢
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 2017-07-10
      • 2021-11-15
      • 2021-04-25
      • 2021-05-20
      相关资源
      最近更新 更多