简体   繁体   English

如何阻止我的机器人响应 @everyone ping,但同时响应 discord.py 中的 @Bot ping?

[英]How do I stop my bot from responding to @everyone pings but also respond to @Bot pings in discord.py?

I have a bot that responds when I ping it by tagging its ID but it also responds to @everyone pings.我有一个机器人,当我通过标记其 ID 对其进行 ping 操作时会做出响应,但它也会响应 @everyone pings。 How do I filter those out?我如何过滤掉那些? I've tried using an if statement to filter out @everyone and the ID of @everyone but then the bot doesn't respond to normal pings.我尝试使用 if 语句过滤掉 @everyone 和 @everyone 的 ID,但是机器人不会响应正常的 ping。 Here's the current code:这是当前代码:

@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)

I'm using the commands extension from the rewrite.我正在使用重写中的命令扩展名。 The first block of the code is the filter for @everyone and the second part, below the else statement is the response to a ping.代码的第一块是@everyone 的过滤器,第二部分在else语句下面是对 ping 的响应。

You can use the message.mention_everyone attribute to filter out @everyone and @here-pings like so:您可以使用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

Just check if the bot was mentioned in the message, instead of check if it wasn't an everyone ping只需检查消息中是否提到了该机器人,而不是检查它是否不是所有人 ping

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord.py - 如何检测用户是否提到/ping bot - Discord.py - how to detect if a user mentions/pings the bot Discord ping 与纯文本,以及如何使用我的机器人响应 ping - Discord ping vs plaintext, and how to respond to pings with my bot 如果另一个用户 ping 用户 discord.py,如何让机器人显示用户的信息 - How to make a bot display a user's info if another user pings that user discord.py (discord.py) 我的机器人的 whois 命令也显示用户的角色,将“@everyone”显示为“@@everyone”我该如何解决这个问题 - (discord.py) My bot's whois command which also displays the user's roles displays “@everyone” as “@@everyone” How do I fix this Discord.py 如何让我的机器人在重复用户参数时无法 ping 所有人 - Discord.py How do I make my bot not ping everyone when it repeats a users argument Discord bot ping 然后卡住 - Discord bot pings and then is stuck 如何阻止我的机器人向 discord.py 发送垃圾邮件 - How do I stop my bot from spamming discord.py 如何让我的机器人仅响应对特定消息的反应? | discord.py - How do I get my bot to respond only to reactions on a specific message? | discord.py 如何使用机器人对所有人进行DM - discord.py - How to DM everyone with a bot - discord.py 如何在heroku上托管我的discord.py机器人? - How do I host my discord.py bot on heroku?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM