只是想知道我如何有 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)
对于 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)