【问题标题】:Discord.py ignore specified channelDiscord.py 忽略指定频道
【发布时间】:2021-01-06 20:32:19
【问题描述】:

我有这段代码,可以将已删除的消息记录到我不和谐的频道中。但是,我想知道如何让它忽略一个指定的频道,我不希望它记录已删除的消息。我需要在我的代码中编辑什么来做到这一点?谢谢。

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

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

【问题讨论】:

    标签: discord discord.py


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-24
      • 2020-06-20
      • 2020-12-07
      • 1970-01-01
      • 2021-03-24
      • 2021-02-18
      • 2021-06-08
      • 2021-10-29
      相关资源
      最近更新 更多