【问题标题】:Discord bot : How to know when a user is pinged in the message and not because it's a replyDiscord bot:如何知道用户何时在消息中被 ping,而不是因为它是回复
【发布时间】:2021-08-20 08:40:03
【问题描述】:

目标:

我正在尝试让机器人在特定用户在消息中被 ping 时发送消息。
所以我尝试了这个:

if (message.mentions.has(bot.users.cache.get(userID)))

它工作正常,如果你 ping 用户,机器人会发送一条消息。例外...

问题:

当您只是回复用户而不在消息中 ping 用户时,机器人也会做出反应,我不希望这样。
我能看到的唯一方法是:

if (message.content.includes(userID))

【问题讨论】:

    标签: discord.js ping reply


    【解决方案1】:

    您应该直接检查它们是否在消息中被 ping 通。

    const userRegex = new RegExp(`<@!?${userID}>`)
    if (message.content.match(userRegex)) {
      //user has been mentioned and it was not because of reply
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-30
      • 2021-05-09
      • 2022-01-09
      • 2021-12-18
      • 1970-01-01
      • 2021-05-15
      • 2020-12-24
      相关资源
      最近更新 更多