如何在一个参数中放入多个单词discord.py

Ste*_*d25 2 discord.py

我正在开发一个使用discord.py的机器人,我想要一个命令来让你设置机器人正在玩的游戏,但我不知道如何提出允许空格的参数。

我试图提出两个论点,但如果你想要一个词,它就会显示为错误。


@client.command()
async def game(gameplay):
    #do things
Run Code Online (Sandbox Code Playgroud)

我希望“游戏性”这一论点包含多个单词。有人可以帮忙吗?

Vul*_*pex 6

@client.command()
async def game(ctx, *args):
    # args contains all arguments written after the command i.e !game game i want to play
    # print(" ".join(args[:])) will print "game i want to play"
Run Code Online (Sandbox Code Playgroud)

正如您在示例中看到的,*args将包含命令后写入的所有内容。ctx 将是上下文。希望这可以帮助。