python - 轮询命令 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 你是人类是的不是(这就是我想要的)
谢谢!
解决方案
调用命令时,将字符串放在引号中会导致它被视为一个参数:
/poll "You are human" yes no
推荐阅读
- powerbi - 在 Power BI 中筛选大约一项度量
- vba - 在 Access VBA 中将表记录添加到列表框
- c# - 如何将文本而不是值从选择列表传递到 Asp .Net Core 中的控制器
- excel - ADO 连接后 Excel 崩溃
- html - 如果:target 不存在,如何为元素设置默认样式
- mysql - Redis、Cassandra等分布式数据库在微服务架构中是如何工作的?
- c# - 代码中的值与 excel 文件中的文本不同
- php - 在 Laravel 中软删除后更新隐藏值
- microsoft-dynamics - 在子网格中添加超链接
- ruby-on-rails - Faye 请求不安全的脚本