discord.py轮询命令错误



我基本上想做一个投票命令,接受用户输入的表情符号,并将其用作反应,但我也想让它有多个表情符号被允许使用,所以如果有超过2个选项,它将与这个命令一起工作。

的例子:!poll test:white_large_square::black_large_square::tired_face:

回溯:

Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
TypeError: poll() missing 2 required keyword-only arguments: 'em1' and 'em2'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: poll() missing 2 required keyword-only arguments: 'em1' and 'em2'

代码:

async def poll(ctx, *, message, em1, em2, em3=None, em4=None, em5=None, em6=None, em7=None, em8=None, em9=None, em10=None):
authorperms = ctx.author.permissions_in(ctx.channel)
if authorperms.manage_messages:
emb = discord.Embed(title="📜Poll📜", color=discord.Color.red())
emb.add_field(name="Question", value=f"{message}")
emb.set_footer(text="Official GNAG Discord Bot Made by Lukeee#2222")
msg = await ctx.channel.send(embed=emb)
else:
embed = discord.Embed(title="Permission Denied.",
description="You don't have permission to execute this command.",
color=0xff0000)
embed.set_footer(text="Official GNAG Discord Bot Made by Lukeee#2222")
await ctx.send(embed=embed)
if em1:
await msg.add_reaction(em1)
if em2:
await msg.add_reaction(em2)
if em3:
await msg.add_reaction(em3)
else:
print("only 2 emojis ig. :C")
if em4:
await msg.add_reaction(em4)
else:
print("Only 3 emojis ig. :C")
if em5:
await msg.add_reaction(em5)
else:
print("Only 4 emojis ig. :C")
if em6:
await msg.add_reaction(em6)
else:
print("Only 5 emojis ig. :C")
if em7:
await msg.add_reaction(em7)
else:
print("Only 6 emojis ig. :C")
if em8:
await msg.add_reaction(em8)
else:
print("Only 7 emojis ig. :C")
if em9:
await msg.add_reaction(em9)
else:
print("Only 8 emojis ig. :C")
if em10:
await msg.add_reaction(em10)
else:
print("Only 9 emojis ig. :C")```


From the docs:

由于解析歧义,您只能有一个关键字参数。

要简单地修复代码,请删除仅关键字参数(*)

async def poll(ctx, message, em1, em2, em3=None, em4=None, em5=None, em6=None, em7=None, em8=None, em9=None, em10=None):

你所要做的就是保留这段代码,然后把你的问题放在引号里,例如:!poll "Cats Or Dogs?"猫狗:::

最新更新