so I have this code(discord.py):
@client.command()
async def buyrole(ctx, role: int):
print(serverdata[f'{ctx.guild}'][role].split(' '))
print(int(serverdata[f'{ctx.guild}'][role].split(' ')[1]))
for i in range(baldata[f'{ctx.guild}'].__len__()):
if(i):
if(f'{str(ctx.message.author).split("#")[0]}' in baldata[f'{ctx.guild}'][i]):
userbal = int(baldata[int(baldata[f'{ctx.guild}'][i].split('#')[1].split(' ')[1])])
if(userbal > int(serverdata[f'{ctx.guild}'][role].split(' ')[1])):
buy = discord.utils.get(ctx.guild.roles, name=serverdata[f'{ctx.guild}'][role].split(' ')[0])
if(not buy in ctx.message.author.roles):
add = int(baldata[f'{ctx.guild}'][i].split('#')[1].split(' ')[1]) - int(serverdata[f'{ctx.guild}'][role].split(' ')[1])
baldata[f'{ctx.guild}'][i] = f'{ctx.message.author} {add}'
await ctx.message.author.add_roles(buy)
await ctx.send(f'role {buy} purchased')
else:
await ctx.send('you already have that role')
else:
await ctx.send('you do not have enough money to buy that role, keep being active!')
and I get this error and I don't know what it means and how to fix it:
Ignoring exception in command buyrole:
Traceback (most recent call last):
File "C:\Users\roeyd\PycharmProjects\roleShop\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/roeyd/PycharmProjects/roleShop/main.py", line 97, in buyrole
userbal = int(baldata[int(baldata[f'{ctx.guild}'][i].split('#')[1].split(' ')[1])])
KeyError: 20
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\roeyd\PycharmProjects\roleShop\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\roeyd\PycharmProjects\roleShop\venv\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\roeyd\PycharmProjects\roleShop\venv\lib\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: KeyError: 20
thank you so so much for helping I really appreciate it I am new and having some trouble so helping is incredible