如何将多个单词放在一个参数discord.py中 [英] How do I put multiple words in one argument discord.py

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

问题描述

我正在开发一个使用discord.py的机器人,并且我想拥有一个命令,该命令可以让您设置该机器人正在玩的游戏,但是我不知道如何创建允许空格的参数。



我尝试输入2个参数,但是如果您想要一个单词,它将显示为错误。

  
@ client.command()
异步定义游戏(游戏性):
#做事情

我希望参数游戏性中包含多个单词。有人可以帮忙吗?

解决方案

  @ client.command()
异步def game(ctx,* args):
#args包含命令后写的所有参数,即!我要玩的游戏!
#print( .join(args [:]))将打印我想玩的游戏

如示例所示, * args 将包含命令后编写的所有内容。 ctx将是上下文。希望这会有所帮助。


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.

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

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"

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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆