【问题标题】:How to listen for a mention of CurrentUser as a Discord bot如何听取 CurrentUser 作为 Discord 机器人的提及
【发布时间】:2023-02-08 20:32:00
【问题描述】:

当其他用户在聊天中提到我的机器人时,我希望我的机器人能够捕捉到。我试过了

message.MentionedUsers.contains(client.CurrentUser)

但这会返回 false,我相信是因为 MentionedUsers 是 SocketGuildUser 的集合,而 client.CurrentUser 是 SocketUser

我是否需要遍历 MentionedUsers 来查找 user.id?或者有更直接的方法吗?

使用 Discord.Net 3.8.1

【问题讨论】:

    标签: discord discord.net


    【解决方案1】:

    我无法解释为什么你的解决方案不起作用,但我有另一种方法可以让你检查你的机器人是否在使用 linq 的提到的用户中:

    //you have to add this using if you havent yet
    using System.Linq;
    
    
    if(message.MentionedUsers.Any(m => m.Id == client.CurrentUser.Id))
    {
       //this code will be fired if your bot was mentioned in the message
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-17
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 2019-11-19
      • 2021-07-30
      • 1970-01-01
      • 2021-09-03
      • 2021-05-09
      相关资源
      最近更新 更多