机器人只需要一个命令

Fle*_*xes 6 python python-3.x discord discord.py

我正在尝试制作一个机器人,当您输入例如“!say hello world”时,机器人会回复“Hello World”。但是当我尝试做空间时它不起作用。

因此,当我简单地输入“!say Hello”时,它会显示:

如您所见,它工作正常,但是当我放一个空格例如“!say hello world”时,它显示了以下内容:

正如你所看到的,它只打印“Hello”,就像我没有说“World”一样。

这是我的代码:

@client.command()
async def say(ctx, arg):
    await ctx.send(arg)
Run Code Online (Sandbox Code Playgroud)

Jon*_*nas 4

请参阅此处:命令

由于位置参数只是常规的 Python 参数,因此您可以拥有任意数量的参数:

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

有时您希望用户传递不确定数量的参数。该库支持这一点,类似于在 Python 中完成变量列表参数的方式:

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