首页 > 解决方案 > 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)

如果您可以让我知道要在此代码中添加什么以使其忽略一个频道,但适用于所有其他频道,那就太棒了。谢谢!

标签: discorddiscord.py

解决方案


您可以检查删除的消息通道 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)

推荐阅读