discord - Discord.py 忽略指定频道
问题描述
我有这段代码,它将已删除的消息记录到我不和谐的频道中。但是,我想知道如何让它忽略一个指定的频道,我不希望它记录已删除的消息。我需要在我的代码中编辑什么来做到这一点?谢谢。
@bot.event
async def on_message_delete(message):
embed=discord.Embed(title="{} deleted a message".format(message.author), description=" ", color=0x55246c)
embed.add_field(name= message.content ,value="Message logging coded by ProfessorAdams.", inline=True)
channel=bot.get_channel(CHANNEL_ID)
await channel.send(embed=embed)
如果您可以让我知道要在此代码中添加什么以使其忽略一个频道,但适用于所有其他频道,那就太棒了。谢谢!
解决方案
您可以检查删除的消息通道 id 是否等于您希望它忽略的通道 id。
@bot.event
async def on_message_delete(message):
if message.channel.id == <IGNORED_CHANNEL_ID>: #Enter the channel id that you want to ignore
return
embed=discord.Embed(title="{} deleted a message".format(message.author), description=" ", color=0x55246c)
embed.add_field(name= message.content ,value="Message logging coded by ProfessorAdams.", inline=True)
channel=bot.get_channel(CHANNEL_ID)
await channel.send(embed=embed)
推荐阅读
- postgresql - Postgres JSONB - 子对象的所有动态(整数)属性的索引
- php - array_key_exists 没有按预期工作
- android - 如何使用单个按钮实现 EditText 和保存编辑的文本?
- wordpress - 如果在 Woocommerce 中购买了特定产品,则向特定地址发送电子邮件通知
- swift - 从一个 IBAction 到另一个 swift 的浮点数
- regex - 正则表达式 unix 命令
- c++ - LuaC 库:某些函数的访问冲突
- createjs - CreateJS 使 Cache Empty 不断占用内存?
- python - 如何在 python 中从 MultiIndexed pandas 数据框创建数组树
- php - Symfony 4 骨架,调用 php binance api 和 php binance api 速率限制器时出错