A
A
Andrey Volchara2020-10-29 12:28:16
Python
Andrey Volchara, 2020-10-29 12:28:16

Why does ctx.guild.id return None in a request?

I am writing a leaderboard, everything works on sqlite, for some reason it works on postgres.
I get an error TypeError: 'NoneType' object is not iterable

@client.command(aliases= ['leaderboard', 'lb', 'top'])
async def __leaderboard(ctx):
    embed = discord.Embed(title = 'Топ 10 сервера')
    counter = 0

    for row in cursor.execute("SELECT name, cash FROM users WHERE server_id = {} ORDER BY cash DESC LIMIT 10".format(ctx.guild.id)):
        counter += 1
        embed.add_field(
            name = f'# {counter} | {row[0]}',
            value = f'Баланс: {row[1]} коинов',
            inline = False
        )
    await ctx.send(embed = embed)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2020-10-29
@vollchara

Missing fetchall(). By itself, cursor.execute returns None. And as already noted here, you don’t need to use string formatting to substitute SQL query parameters, use the normal syntax (via %s and data transfer), after all, an example was already given in the previous question.
for row in cursor.execute(...).fetchall():

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question