【问题标题】:How do I stop my bot from responding to @everyone pings but also respond to @Bot pings in discord.py?如何阻止我的机器人响应@everyone pings,但也响应discord.py 中的@Bot pings?
【发布时间】:2021-05-24 21:05:54
【问题描述】:

我有一个机器人,当我通过标记其 ID 对其进行 ping 操作时,它会做出响应,但它也会响应 @everyone ping。我如何过滤掉那些?我尝试使用 if 语句过滤掉 @everyone 和 @everyone 的 ID,但是机器人不会响应正常的 ping。这是当前代码:

@bot.listen('on_message')
async def on_ping(message):
  if bot.user.mentioned_in(message):
    if "<@747577395086884998>" in message.content:
      return
    else:
      channel = message.channel
      embed=discord.Embed(color=0x0fd249)
      file = discord.File("logo.png", filename="image.png")
      embed.set_author(name="Fallen Bot", icon_url="attachment://image.png")
      embed.add_field(name="Hi! I'm Fallen Bot!", value=f"My prefix is, `{bot.command_prefix}` and you can use `{bot.command_prefix}help` for help!", inline=False)
      await channel.send(file=file, embed=embed)

我正在使用重写中的命令扩展名。代码的第一块是@everyone 的过滤器,第二部分在else 语句下方是对ping 的响应。

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    您可以使用message.mention_everyone 属性过滤掉@everyone 和@here-pings,如下所示:

    @bot.listen('on_message')
    async def on_ping(message):
        if message.mention_everyone:
            return
        else:
            # this is a real ping, do your thing
    

    【讨论】:

      【解决方案2】:

      只需检查消息中是否提到了该机器人,而不是检查它是否不是所有人 ping

      if "<!@100>" in message.content: # 100 is the bots id, change it to yours
          # handle the ping here
      

      【讨论】:

      • 这不会让机器人响应 @Bot 角色 ping,但是
      • @LukasThaler 确实,我不知道如何排除@大家 ping
      猜你喜欢
      • 2021-08-18
      • 2021-11-03
      • 2018-07-09
      • 2018-11-17
      • 2011-07-10
      • 2021-10-06
      • 2022-12-07
      • 2021-02-26
      • 2020-02-22
      相关资源
      最近更新 更多