【问题标题】:How to check if a certain user was mentioned [closed]如何检查是否提到了某个用户[关闭]
【发布时间】:2021-06-11 22:56:08
【问题描述】:

我正在尝试检查消息中是否提到了用户 (@user)。这是我目前拥有的:

    } if (message.content.includes('<@796406791323516999>')) {
        message.channel.bulkDelete(1);
        message.channel.send('User mention was detected')
    }

(这包含在客户端中。在检测何时发送消息时)

我在这里做错了什么?

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    您可以使用Mentions#members#has 和成员的 ID 来检查是否有任何提及,以及该成员是否是提及之一。

    const mentions = message.mentions.members;
    
    if (!mentions) return message.channel.send('No Mentions Error Message.');
    
    if (mentions.has('796406791323516999')) {
      message.channel.bulkDelete(1);
      message.channel.send('User mention was detected');
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-24
      • 2011-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多