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

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

本文介绍了如何在一个参数中放入多个单词 discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I am working on a bot that uses discord.py, and I want to have a command that lets you set the game the bot is playing, but I don't know how to make an argument that allows spaces.

我尝试提出 2 个参数,但如果您想要 一个 字,它将显示为错误.

I have tried to make 2 arguments, but then if you want one word it will show up as an error.


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

我希望参数gameplay"包含多个单词.有人可以帮忙吗?

I want the argument "gameplay" to have multiple words in it. Can someone please help?

推荐答案

@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 将是上下文.希望这会有所帮助.

As you can see in the example, *args will contain everything written after the command. ctx will be the context. Hope this helps.

这篇关于如何在一个参数中放入多个单词 discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:20