#Database Command Issue

1 messages · Page 1 of 1 (latest)

glad cradle
#

I have multiple moderation commands and one of them is called /moderation strike. How it works is that it is supposed to add a log to an Sqlite3 Database whenever an action is logged however for some reason, for one, I cannot even create the database even though I don't get any errors. And when I run a command, it comes up with the error shown in the picture. Could someone help me, thanks! (Note: If I remove await addlog_strike(member, reason) in the /moderation strike command which is supposed to log it onto the database, the command comes up with no errors so there is an issue with the database code).

I'm new to databases so I'd appreciate the help!

on_ready()

@bot.event
async def on_ready():
    db = sqlite3.connect("action_logs.sqlite")
    cursor = db.cursor()
    cursor.execute("CREATE TABLE IF NOT EXISTS action_logs(id INTERGER, type INTERGER, user INTERGER, reason TEXT, duration INTERGER)")
    print(f"[✅] We have logged in as {bot.user}")

/moderation strike command

@moderation.command(description = "Can be used to give someone a strike")
async def strike(ctx, member: Option(discord.Member, description = "Choose a Member"), reason: Option(str, description = "State a reason")):
    if member.id == ctx.author.id:
        embed = discord.Embed(title = "Error", description="You cannot give yourself a strike.", color = discord.Color.dark_orange())  
        await ctx.respond(embed=embed)
    else:
        await addlog_strike(member, reason)
        embed = discord.Embed(title ="Moderation Strike",description=f"<@{member.id}> has been sucesfully been given a strike.", color = discord.Color.blue())  
        embed.add_field(name = "Moderator", value=f"{ctx.author.mention}", inline=True)
        embed.add_field(name = "Reason", value=f"{reason}")
        embed.add_field(name = "ID", value="N/A")
        await ctx.respond(embed=embed)
    print(f"[🔧] {ctx.author} ({ctx.author.id}) used /moderation strike")
#

Here is the code for when it actually does the addlog_strike (I ran out of the character limit)

async def addlog_strike(member, reason):
    db = sqlite3.connect("action_logs.sqlite")
    cursor = db.cursor()
    id4 = get_random_string()
    cursor.execute("INSERT INTO action_logs (id, type, user, reason, duration) VALUES (?, ?, ?, ?, ?)", get_random_string(), "Strike", member.id, reason)
    db.commit()
shrewd scroll
#

also, good idea to use asqlite or aiosqlite

glad cradle
#

I’ll try those out then

#

Thank you