python - 如何阻止我的机器人响应@everyone pings,但也响应discord.py 中的@Bot pings?
问题描述
我有一个机器人,当我通过标记其 ID 对其进行 ping 操作时会做出响应,但它也会响应 @everyone pings。我如何过滤掉那些?我尝试使用 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 的响应。
解决方案
您可以使用该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
推荐阅读
- javascript - 使对象面向鼠标光标
- delphi - 从 Delphi 应用程序在 PowerPoint 幻灯片中添加链接
- javascript - async 和 await 调用一个 api 来响应,
- sql - 如何验证表的数据和
使用 BigQuery SQL 引发错误? - daml - DAML :- 无法从其数组参数的另一个模板将当事方设置为观察者,请提供相同的帮助
- azure - Azure PowerShell runbook:Invoke-RestMethod 的 -InFile 标志未按预期工作
- python - 查找不同 csv 文件之间列标题的差异
- node.js - 我们可以将 app.get() 与 nodejs 中的任何路径一起使用吗?
- c++ - “检测到 CRT ......堆损坏”错误与析构函数
- crm - 是否可以在 Zoho CRM 中自动从销售订单转换为采购订单?