I was coding a Tax calculator system and when I'm using the function It gives me the error : discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: unsupported operand type(s) for : 'int' and 'NoneType'
, I tried Everything but it didn't work.
Here's the function (tax calculator):
async def tax(args):
args3 = 5
protax= round(int(args)*args3/100)
if protax == 0:
protax = 1
And here's where I called it:
c.execute("SELECT price FROM netflix")
netfprice = c.fetchall()
netprice = netfprice[0][0]
netprix = await tax(netprice*amount)
embed = discord.Embed(
title="transfer system",
description=f"Please transfer:{netprice netprix}"
)
the full traceback:
Ignoring exception in command buy:
Traceback (most recent call last):
File "C:\Users\sidal\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 127, in wrapped
ret = await coro(arg)
File "C:\Users\sidal\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 911, in _invoke
await self.callback(ctx, **kwargs)
File "c:\Users\sidal\Desktop\Sidtho\main.py", line 227, in buy
description=f"Please transfer:{netprice netprix}"
TypeError: unsupported operand type(s) for : 'int' and 'NoneType'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\sidal\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\bot.py", line 1008, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\sidal\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 359, in invoke
await injected(ctx)
File "C:\Users\sidal\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\commands\core.py", line 135, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: unsupported operand type(s) for : 'int' and 'NoneType'
CodePudding user response:
Your tax()
function isn't returning anything, so by default it returns None.
I suppose you want to send the protax
variable. If that is the case, this code should work:
async def tax(args):
args3 = 5
protax= round(int(args)*args3/100)
if protax == 0:
protax = 1
return protax