LZulb
LZulb

Reputation: 23

Nothing happens with this command and don't know why. Everything looks fine

class EconomyCog(commands.Cog, name="Help"):

def __init__(self, bot):
    self.bot = bot

@commands.command()
async def Money(self, ctx, member:discord.Member):
    member = ctx.author
    member_id = ctx.author.id
    db = sqlite3.connect("main.sqlite")
    cursor = db.cursor()
    cursor.execute(f"SELECT member_id FROM main WHERE member_id = {member_id}")
    result = cursor.fetchone()
    if result is None:
        sql = (f"INSERT INTO main(member_id, money) VALUES(?, ?)")
        val = (member_id, 500)
        cursor.execute(sql, val)
        db.commit
        await ctx.send("Because you didn't have an account, I just made one for you!")
        db.close
        cursor.close
    elif result is not None:
        db = sqlite3.connect("main.sqlite")
        cursor = db.cursor()
        cursor.execute(f"SELECT * FROM main WHERE member_id = {member_id}")
        result = cursor.fetchone()

        embed = discord.Embed(title = f"{member}'s Money", description = f"{result[1]} <:BitCoin:929595745500274689>", color = discord.Colour.random)
        await ctx.send(embed=embed)

I don't get any errors but also when the command is triggered nothing happens. You have any clue to why it won't work?

Upvotes: 1

Views: 55

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54718

These lines do nothing. They don't call functions, they just mention the function objects:

        db.commit
...
        db.close
        cursor.close

It's exactly like writing:

        7

It is syntactically legal, but does nothing.

To call them, you MUST use parens. Also note that you don't need to refetch the member record in the else; you can have that first query serve both purposes:

async def Money(self, ctx, member:discord.Member):
    member = ctx.author
    member_id = ctx.author.id
    db = sqlite3.connect("main.sqlite")
    cursor = db.cursor()
    cursor.execute(f"SELECT * FROM main WHERE member_id = ?", (member_id,))
    result = cursor.fetchone()
    if result is None:
        sql = (f"INSERT INTO main(member_id, money) VALUES(?, ?)")
        val = (member_id, 500)
        cursor.execute(sql, val)
        db.commit()
        await ctx.send("Because you didn't have an account, I just made one for you!")
    else:
        embed = discord.Embed(title = f"{member}'s Money", description = f"{result[1]} <:BitCoin:929595745500274689>", color = discord.Colour.random)
        await ctx.send(embed=embed)
    cursor.close()
    db.close()

Upvotes: 1

Related Questions