【问题标题】:Bot Mentions Discord.pyBot 提到 Discord.py
【发布时间】:2022-02-06 09:30:11
【问题描述】:
  if client.user.mentioned_in(message):
    await ctx.send("Hi!")

所以我希望我的机器人回复@提及它的任何人。它确实可以正常工作,但它会响应@everyone 和@here pings 的唯一问题。这可能很简单,我想多了,但我只想知道是否有任何方法可以让机器人响应它实际提到的消息,而不是 @everyone 或 @here pings?

【问题讨论】:

  • @meph 这并没有做任何事情。机器人仍会在此处回复@所有人和@。我认为我的问题不够清楚,但感谢您提供帮助。
  • 哦,我的错。我没有正确阅读它。我会删除这种无意义的。对不起

标签: python discord discord.py


【解决方案1】:

检查机器人的用户ID是否在消息内容中。请尝试以下操作:

    if str(client.user.id) in message.content:
        await ctx.send("Hi!")

【讨论】:

    【解决方案2】:

    嗯,试试这个

    @client.event
    async def on_message(message):
      if f"<@!{client.user.id}>" in message.content:
        await ctx.send("Hi!")
    

    【讨论】:

      【解决方案3】:

      你可以使用

      @client.event
      async def on_message(message):
      

      然后检测消息是否提到了bot:

      if client.user.mentioned_in(message):
          await message.channel.send("Hi!")
      

      文档:https://docs.pycord.dev/en/master/api.html?highlight=mentioned#discord.ClientUser.mentioned_in

      【讨论】:

        猜你喜欢
        • 2021-01-21
        • 2023-03-24
        • 1970-01-01
        • 2019-05-28
        • 2018-12-02
        • 2021-09-19
        • 2021-04-04
        • 2019-08-22
        • 2020-02-22
        相关资源
        最近更新 更多