首页 > 解决方案 > 轮询命令 discord.py

问题描述

不和谐

我尝试为投票系统创建命令并遇到问题。命令如下:

@commands.command(pass_context = True)
async def poll(self, ctx, question, *options: str):
    author = ctx.message.author
    server = ctx.message.server

    if not author.server_permissions.manage_messages: return await self.bot.say(DISCORD_SERVER_ERROR_MSG)

    if len(options) <= 1:
        await self.bot.say("```Error! A poll must have more than one option.```")
        return
    if len(options) > 2:
        await self.bot.say("```Error! Poll can have no more than two options.```")
        return

    if len(options) == 2 and options[0] == "yes" and options[1] == "no":
        reactions = ['', '']
    else:
        reactions = ['', '']

    description = []
    for x, option in enumerate(options):
        description += '\n {} {}'.format(reactions[x], option)

    embed = discord.Embed(title = question, color = 3553599, description = ''.join(description))

    react_message = await self.bot.say(embed = embed)

    for reaction in reactions[:len(options)]:
        await self.bot.add_reaction(react_message, reaction)

    embed.set_footer(text='Poll ID: {}'.format(react_message.id))

    await self.bot.edit_message(react_message, embed=embed)

我的问题是:如何使用命令提出我提出的问题以获得更多单词。如果我现在使用更多单词,我会将它们作为选项阅读并得到错误。

Ex 1 : /poll You are human yes no (只将“you”读作问题,其余为选项。)

Ex 2 : /poll 你是人类是的不是(这就是我想要的)

谢谢!

标签: pythondiscorddiscord.py

解决方案


调用命令时,将字符串放在引号中会导致它被视为一个参数:

 /poll "You are human" yes no

推荐阅读