T
T
tatsuki12021-11-27 00:31:02
Python
tatsuki1, 2021-11-27 00:31:02

Error in sqlite3, help?

Greetings. I ran into a problem, writes that sqlite.cursor does not support the "<" sign, or I did something wrong.

TypeError: '<' not supported between instances of 'sqlite3.Cursor' and 'int'


@client.command(aliases = ['казино','casino'])
async def casino(ctx, arg:int=None):
    winandlosing = ['Выиграли', 'Проиграли']
    if arg is None:
        await ctx.send(f'{ctx.author.mention}, укажите количество на которое хотите сыграть')
    else:
        cash = cursor.execute(f"SELECT cash FROM users WHERE id = {ctx.author.id}")
        if cash < arg:
            await ctx.send(f'{ctx.author.mention}, у вас недостаточно денег.')
        else:
            da = await ctx.send(f'{ctx.author.mention}, вы {random.choice(winandlosing)}')
            if da == 'Выиграли':
                win = arg*2
                cursor.execute(f'UPDATE users SET cash = {win} WHERE id = {ctx.author.id} ')
                await ctx.send(f'{ctx.author.mention}, вы выиграли, поздравляю, ваш выигрыш удвоен.')
            if da == 'Проиграли':
                cursor.execute(F"UPDATE users SET cash = {arg} WHERE id = {ctx.author.id}")
                await ctx.send(f'{ctx.author.mention}, вы проиграли, в следующий раз повезёт.')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2021-11-27
@tatsuki1

cursor.execute returns an iterable result generator. You can either run through it:

for row in cursor.execute(...):
   cash, = row
   # или
   cash = row[0]

Or do a fetchall:
res = cursor.execute(...)
res_list = res.fetchall()
cash = res_list[0][0]

R
Ronald McDonald, 2021-11-27
@Zoominger

Convert types.
You have a mistake here:
if cash < arg:
You are comparing them as numbers, but, apparently, cash is not a number. Do:
(int)cash
Should help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question