#something wrong with json and hikari. might be dumb
1 messages · Page 1 of 1 (latest)
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
so i should use user ids?
okay ill do that
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
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 ;-; )
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
i know sql and shii
well then dont use a json

