执行另一个命令时,如何取消on_message事件?我的代码:
@client.event
async def on_message(message):
channel = message.author
def check(m):
return m.channel == message.channel and m.author != client.user
if message.content.startswith("!order"):
await channel.send("in game name")
in_game_name = await client.wait_for('message', check=check)
await channel.send("in game ID")
in_game_ID = await client.wait_for('message', check=check)
else:
await client.process_commands(message)
答案 0 :(得分:0)
on_message实际上仅应保留给需要on_message事件的事件(例如,如果您正在编写自动审核功能)。
对于命令,应该在功能之前使用@client.command
或@bot.command
装饰器。 Here是命令的用法。以下是一些您为什么应该使用命令的原因(直接从discord.py discord上的?tag命令获得):
Client
做所有事情如果您有任何疑问,请随时对此答案发表评论!
答案 1 :(得分:0)
您可以将on_message
事件放在嵌齿轮内。这样,on_message
事件(或任何其他事件/命令)将仅在嵌齿轮处于活动状态时触发。
class Foo(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message):
# Do something
要注册齿轮(激活):
bot.add_cog(Foo(bot))
要移除齿轮(停用):
bot.remove_cog('Foo')