discord.py - 如何在命令中有 2 个参数?

Sli*_*eYT 0 python discord.py

只是想知道我如何有 2 个参数,例如

User: ?text A B
Bot: A B
Run Code Online (Sandbox Code Playgroud)

像“arg1”和“arg2”示例:

await bot.say({} {}.format(arg1, arg2))
Run Code Online (Sandbox Code Playgroud)

Meh*_*vix 6

对于 2 个参数作为 2 个单独的变量,您可以执行以下操作

@bot.command()
async def args(ctx, arg1, arg2):
    await bot.say('You sent {} and {}'.format(arg1, arg2))
Run Code Online (Sandbox Code Playgroud)

或者,如果您想发送作为列表传递的所有参数,您可以执行...根据重写文档

@bot.command()
async def args(ctx, *args):
    await bot.say('`{}` arguments: `{}`'.format(len(args), ', '.join(args)))
Run Code Online (Sandbox Code Playgroud)

或者,如果您想将所有内容作为一个参数发送,您可以这样做(文档):

@bot.command()
async def args(ctx, *, arg):
    await bot.say(arg)
Run Code Online (Sandbox Code Playgroud)