我想确保我的机器人只响应命令/消息并仅在1个特定通道中响应这是否可能我尝试了多种变化而没有成功。如果我可以为任何事件定义它,那就更好了。有人有任何想法吗?
你可以在message.channel
事件中检查on_message
,如果它符合你的标准,在这种情况下是一个特定的通道,那么就做process_commands
。
下面是一个例子,其中!ping
命令仅在channel.name
为“general”时才有效。
from discord.ext import commands
client = commands.Bot(command_prefix='!')
@client.command()
async def ping():
await client.say('Pong')
@client.event
async def on_message(message):
if message.channel.name == 'general':
await client.process_commands(message)
client.run('token')