Discord.py是否可以将命令拆分为多个消息?

时间:2020-11-12 08:04:53

标签: python discord.py

例如,如果命令具有多个参数,例如:

@client.command()
async def command(ctx, channel, time, prize):
     //code

我如何做到这一点,以便它在每条消息中都要求一个不同的论点?像这样: Bot:什么渠道? 用户:(频道名称) Bot:多长时间? 用户:(时间) Bot:奖金是多少? 使用者:(prize)

如果有帮助,我正在制造一个免费机器人。

1 个答案:

答案 0 :(得分:0)

使用wait_for。您甚至可以指定机器人应等待的时间。

示例:

@client.command()
async def some_command_name(ctx):
    def check(m):
        return m.author == ctx.author and m.channel == ctx.channel
    try:
        await ctx.send("Channel?")
        channel = await client.wait_for('message', check=check, timeout=60)
        await ctx.send("Time?")
        time    = await client.wait_for('message', check=check, timeout=60)
        await ctx.send("Prize?")
        prize   = await client.wait_for('message', check=check, timeout=60)
    except asyncio.TimeoutError:
        # do something