首页 > 解决方案 > 如何让机器人忽略 discord.py 中的某些频道?

问题描述

我正在尝试制作一个机器人,当他们说出某些关键字时将成员重定向到某个频道,但我不希望机器人告诉他们如果他们已经在 #commands 中,则进入 #commands。如何让机器人忽略#commands 中的所有消息?

标签: python-3.xdiscorddiscord.py

解决方案


只需在 on_message 事件中添加一个检查即可返回是否message.channel.id等于#commands 的 id。

@client.event
async def on_message(message):
    #Ignore messages sent in channel with id 1234567890 (#commands channel)
    if message.channel.id == 1234567890:
        return

    #Ignore messages sent by the bot
    if message.author == client.user:
        return

推荐阅读