以逗号分隔的选项
Choices separated by a comma
我是 discord.py
的新手
所以,我有这个简单的代码可以随机选择,但目前它用 space 分隔选择,但我希望它用逗号分隔,这样它就可以随机选择由 a 分隔的句子逗号而不是 space 之后的每个单词。我该怎么做?
@client.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def choose(ctx, *choices: str):
async with ctx.channel.typing():
await asyncio.sleep(1)
await ctx.send("Hmm.. Let me think.")
async with ctx.channel.typing():
await asyncio.sleep(3)
await ctx.send(random.choice(choices))
试试这个:
choices = ','.join(choices).split(' ')
这可能是正确的解决方案。
由于括号的位置,它与之前给出的任何答案都不同。
choices = ','.join(choices.split(' '))
我是 discord.py
的新手所以,我有这个简单的代码可以随机选择,但目前它用 space 分隔选择,但我希望它用逗号分隔,这样它就可以随机选择由 a 分隔的句子逗号而不是 space 之后的每个单词。我该怎么做?
@client.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def choose(ctx, *choices: str):
async with ctx.channel.typing():
await asyncio.sleep(1)
await ctx.send("Hmm.. Let me think.")
async with ctx.channel.typing():
await asyncio.sleep(3)
await ctx.send(random.choice(choices))
试试这个:
choices = ','.join(choices).split(' ')
这可能是正确的解决方案。 由于括号的位置,它与之前给出的任何答案都不同。
choices = ','.join(choices.split(' '))