discord.py 重写 on_message 命令不存在。

问题描述 投票:0回答:1

当我使用 !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!") 

python-3.x discord.py-rewrite
1个回答
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)
© www.soinside.com 2019 - 2024. All rights reserved.