我正在开发一个使用discord.py的机器人,我想要一个命令来让你设置机器人正在玩的游戏,但我不知道如何提出允许空格的参数。
我试图提出两个论点,但如果你想要一个词,它就会显示为错误。
@client.command()
async def game(gameplay):
#do things
Run Code Online (Sandbox Code Playgroud)
我希望“游戏性”这一论点包含多个单词。有人可以帮忙吗?
@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 将是上下文。希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
8045 次 |
| 最近记录: |