当我使用!order
命令时,将发送Not existing command
消息,该如何避免呢?
我的代码:
@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)
await channel.send("cargo type")
cargo_type = await client.wait_for('message', check=check)
await channel.send("cargo limit")
cargo_limit = await client.wait_for('message', check=check)
await channel.send("storage")
storage = await client.wait_for('message', check=check)
await channel.send("priority")
priority = await client.wait_for('message', check=check)
await client.process_commands(message)
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("Not existing command!")
答案 0 :(得分:2)
您可以将process_commands
移到else
块中,以便仅在您的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)
await channel.send("cargo type")
cargo_type = await client.wait_for('message', check=check)
await channel.send("cargo limit")
cargo_limit = await client.wait_for('message', check=check)
await channel.send("storage")
storage = await client.wait_for('message', check=check)
await channel.send("priority")
priority = await client.wait_for('message', check=check)
else:
await client.process_commands(message)