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

问题描述 投票:0回答:1

我正在研究一个使用discord.py的机器人,我希望有一个命令让你设置机器人正在玩的游戏,但我不知道如何制作允许空格的参数。

我试图制作2个参数,但是如果你想要一个单词,它将显示为错误。


@client.command()
async def game(gameplay):
    #do things

我希望论证“游戏玩法”中有多个单词。有人可以帮忙吗?

discord.py
1个回答
-1
投票
@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"

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

© www.soinside.com 2019 - 2024. All rights reserved.