Skip to content
← Back to Community
Discord py KeyError question
Profile icon
Cichlid
from discord.ext import commands from replit import db client = commands.Bot(command_prefix='.') user = "" userID = "" for key, value in db.items(): print(f"{key}:{value}") @client.event async def on_ready(): print(f"We have logged in as {client.user}") @client.event async def on_message(message): if message.author == client.user: return user = message.author.name userID = str(message.author.id) if userID not in db.keys(): db[userID] = { 'Username': user, 'Credits': 0, } if message.content == '.hello': await message.channel.send(f"Hello {user}!") await client.process_commands(message) @client.command() async def add(ctx, amount): db[userID]['Credits'] += amount

I am not sure why the add command isn't working. The purpose of the withdraw command is to add whatever number into the credits (from the dictionary). I keep getting a Key Error but I'm not sure why. I checked whether the keys matched or not and it should work but I probably just need someone else to look at it for another perspective.

Voters
Profile icon
leozinga
Profile icon
Cichlid