Im making a discord python bot using repl's database function and i cant figure out how to delete only one value from the database.
@client.command()
async def addvalue(ctx, arg):
db[str(ctx.author.id)] = [arg]
await ctx.send("value added")
@client.command()
async def removevalue(ctx, arg):
db[str(ctx.author.id)] = db[str(ctx.author.id)] - arg #ik this is a dumb way of trying this, this is just theory obv this wouldnt work
What I had to do was find the index of the of the value that I want to be deleted:
async def removevalue(ctx, arg):
c = 0
for x in db[str(ctx.author.id)]:
if str(arg) in db[str(ctx.author.id)][c]:
del db[str(ctx.author.id)][c]
await ctx.send("Value deleted")
return
else:
c += 1
Note that I put str()
around arg
but I'm pretty sure that was useless. I was just trying everything to fix it.