【发布时间】:2022-10-17 23:43:35
【问题描述】:
我正在尝试创建一个滚动命令,您可以在其中选择上限或将其保留为默认值 (6) 这是我尝试过的:
@bot.slash_command(name="roll", description="Rolls a dice", guild_ids=[824342611774144543])
async def roll(ctx, upper_limit: Option(int, required=False)):
d = random.randint(1, upper_limit)
dd = random.randint(1, 6)
if upper_limit == None:
await ctx.respond(dd)
else:
await ctx.respond(d)
当我选择上限时,该命令运行良好,但是当我将其保留为默认值时,它会引发错误
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 768, in process_application_commands
await ctx.command.invoke(ctx)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 306, in invoke
await injected(ctx)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 116, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
【问题讨论】:
标签: python discord bots pycord