(TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType') hikari.lightbulb
(TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType') hikari.lightbulb
@bot.command
@lightbulb.option('modifier','add or subtracts from the original roll', required=False)
@lightbulb.option('op','add or sub', required=False)
@lightbulb.option('sides', 'sides on the die')
@lightbulb.command('r', 'rolls a set of dice')
@lightbulb.implements(lightbulb.PrefixCommand)
async def roll(ctx):
sides, op, mod = ctx.options.sides, ctx.options.op, ctx.options.modifier
sides = sides.split("d")
tDice = sides[0]
tSides = sides[1]
if mod == "": mod = "0"
if op == "-":
mod = int(mod)
mod = 0 - mod
else:
mod = int(mod)
op = "+"
if tDice == "": tDice = "1"
tDice,tSides = int(tDice),int(tSides)
tRoll = [random.randint(1,tSides) for i in range(tDice)]
tRoll1 = int(math.fsum(tRoll))
total = tRoll1 + mod
await ctx.respond(f"{total}")
我正在使用 hikari.lightbulb,老实说我没有发现我的代码有问题,但我一直收到此错误
Traceback (most recent call last):
File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py", line >973, in handle_messsage_create_for_prefix_commands
await self.process_prefix_commands(context)
File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py", line >945, in process_prefix_commands
await context.invoke()
File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/context/base.py", line 276, in invoke
await self.command.invoke(self)
File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/commands/prefix.py", line 112, in invoke
await self(context)
File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/commands/base.py", line 357, in call
return await self.callback(context)
File "/home/toritoab01/GitHub/RPG-Haven/main.py", line 46, in roll
mod = int(mod)
TypeError: int() argument must be a string, a bytes-like object or a >number, not 'NoneType'
上述异常是以下异常的直接原因:
回溯(最后一次调用):
文件“/home/toritoab01/GitHub/RPG-Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py”,第 992 行,在 handle_messsage_create_for_prefix_commands 中
提高 new_exc
lightbulb.errors.CommandInvocationError: 命令 'r' 调用期间发生错误
关于我的“mod”变量有什么建议吗?
我解决了这个问题。所以在 Hikari Lightbulb 中,如果你想做一个不需要的选项,你输入 required= False ,但你也必须输入一个默认值,否则它默认为 None 所以在我的例子中它看起来像这样
@plugin.command
@lightbulb.option('modifier','add or subtracts from the original roll', required=False, default=0)
@lightbulb.option('op','add or sub', required=False, default="+")
@lightbulb.option('sides', 'sides on the die')
@lightbulb.command('r', 'rolls a set of dice')
@lightbulb.implements(lightbulb.PrefixCommand)
问题解决了!
@bot.command
@lightbulb.option('modifier','add or subtracts from the original roll', required=False)
@lightbulb.option('op','add or sub', required=False)
@lightbulb.option('sides', 'sides on the die')
@lightbulb.command('r', 'rolls a set of dice')
@lightbulb.implements(lightbulb.PrefixCommand)
async def roll(ctx):
sides, op, mod = ctx.options.sides, ctx.options.op, ctx.options.modifier
sides = sides.split("d")
tDice = sides[0]
tSides = sides[1]
if mod == "": mod = "0"
if op == "-":
mod = int(mod)
mod = 0 - mod
else:
mod = int(mod)
op = "+"
if tDice == "": tDice = "1"
tDice,tSides = int(tDice),int(tSides)
tRoll = [random.randint(1,tSides) for i in range(tDice)]
tRoll1 = int(math.fsum(tRoll))
total = tRoll1 + mod
await ctx.respond(f"{total}")
我正在使用 hikari.lightbulb,老实说我没有发现我的代码有问题,但我一直收到此错误
Traceback (most recent call last): File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py", line >973, in handle_messsage_create_for_prefix_commands await self.process_prefix_commands(context) File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py", line >945, in process_prefix_commands await context.invoke() File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/context/base.py", line 276, in invoke await self.command.invoke(self) File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/commands/prefix.py", line 112, in invoke await self(context) File "/home/toritoab01/GitHub/RPG->Haven/rpgHaven/lib/python3.9/site->packages/lightbulb/commands/base.py", line 357, in call return await self.callback(context) File "/home/toritoab01/GitHub/RPG-Haven/main.py", line 46, in roll mod = int(mod) TypeError: int() argument must be a string, a bytes-like object or a >number, not 'NoneType'
上述异常是以下异常的直接原因:
回溯(最后一次调用): 文件“/home/toritoab01/GitHub/RPG-Haven/rpgHaven/lib/python3.9/site-packages/lightbulb/app.py”,第 992 行,在 handle_messsage_create_for_prefix_commands 中 提高 new_exc lightbulb.errors.CommandInvocationError: 命令 'r' 调用期间发生错误
关于我的“mod”变量有什么建议吗?
我解决了这个问题。所以在 Hikari Lightbulb 中,如果你想做一个不需要的选项,你输入 required= False ,但你也必须输入一个默认值,否则它默认为 None 所以在我的例子中它看起来像这样
@plugin.command
@lightbulb.option('modifier','add or subtracts from the original roll', required=False, default=0)
@lightbulb.option('op','add or sub', required=False, default="+")
@lightbulb.option('sides', 'sides on the die')
@lightbulb.command('r', 'rolls a set of dice')
@lightbulb.implements(lightbulb.PrefixCommand)
问题解决了!