#something wrong with json and hikari. might be dumb

1 messages · Page 1 of 1 (latest)

languid delta
#

the first question would be

#

why are you using json as a db

#

use an actual database like sqlite

#

secondly

#

usernames are not a unique identifier

#

so in this instance if I changed my username all my warnings would miraculously vanish

versed dragon
#

so i should use user ids?

languid delta
#

yes

versed dragon
#

okay ill do that

languid delta
#

always store user ids if you want to identify users

#

because that is the one thing that cannot change

#

your ID is 1052263113573019649 and you can do nothing about it :P

versed dragon
#

true

#

thanks

#

got this error: AttributeError: 'dict' object has no attribute 'id'

#

my new code:

@bot.command
@lightbulb.option("reason", "reason for the warn")
@lightbulb.option("user", "the user thats gonna get warned", type=hikari.Member)
@lightbulb.add_checks(lightbulb.has_roles(1083717550011076639))
@lightbulb.command("warn", "warn a user")
@lightbulb.implements(lightbulb.SlashCommand)
async def warnuser(ctx):
    user = ctx.options.user
    member = await bot.rest.create_dm_channel(user)
    reason = ctx.options.reason
    await member.send(hikari.Embed(title="You were warned in {}".format(ctx.get_guild().name), description="You were warned for: {}".format(reason), color=(64, 0, 255)))
    await bot.rest.create_message(channel=1085543329040703499, content=f"User <@{user.id}> Was warned for: '{reason}' by: <@{ctx.author.id}>")
    await ctx.respond("User {} Was warned in {}".format(user,ctx.get_guild().name))
    time.sleep(3)
    await ctx.delete_last_response()
    with open('warns.json', 'r') as f:
        report = json.load(f)
    user_found = False
    for user in report['users']:
        if user['name'] == user.id:
            user['reasons'].append(reason)
            user['warns'] += 1
            user_found = True
            break
    if not user_found:
        report['users'].append({
            'name': user.id,
            'reasons': [reason],
            'warns': 1
        })
    with open('warns.json', 'w') as f:
        json.dump(report, f, indent=2)
#

@languid delta (sorry for ping ;-; )

languid delta
#

yeah because user is a dict

#

duh

versed dragon
#

the thing is

#

is that it runs normally on the first warn

#

then it breaks

languid delta
#

but please stop using json as a db

#

learn basic SQL, install sqlite, will take less than 1-2 hours and will save you (and me) a lot of pain

versed dragon
#

i know sql and shii

languid delta
#

well then dont use a json

versed dragon
#

i just dont know how to connect python with a db

#

lmao

languid delta
#

install aiosqlite

#

and do stuffs

versed dragon
#

but i want it in a json

#

@languid delta

#

so like....

languid delta
#

how about

#

you dont

#

there's about 3 reasons I can list right now why that is a terrible idea

#

and there's many more

versed dragon
#

butttttt i wanna do it in a json

#

so like

languid delta
#

welp,I won't assist in stoopid

#

you'll have to do that yourself