问题
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?
回答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"
As you can see in the example, *args
will contain everything written after the command. ctx will be the context. Hope this helps.
回答2:
@client.command()
async def game(ctx, *, args):
ctx.send(args)
来源:https://stackoverflow.com/questions/55665255/how-do-i-put-multiple-words-in-one-argument-discord-py