如何在SQL表中返回值?

2024-05-29 09:44:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Discord.py经济项目,如何在这个SQL表中选择exp并将其返回给嵌入数据库中的用户

sql

代码:

@commands.command()
async def balance(self, ctx):
    db = sqlite3.connect('banco.sqlite')
    cursor = db.cursor()
    cursor.execute(f'SELECT user_id, exp, lvl FROM levels WHERE guild_id = {ctx.author.guild.id} AND user_id = {ctx.author.id}')
    result1 = cursor.fetchone()
    exp = int(result1[1])
        
    for i in range(1,99):
        if exp == i :
            em = discord.Embed(title = f'{ctx.author.name}', color = (0xbbbbbb))
            em.add_field(name = 'LOJINHA 2.0 ',value = int(result1[3]) )
            em.add_field(name = 'LOJINHA 2.0',value = 'C')
            em.set_author(name='LOJINHA 2.0', icon_url='https://i.imgur.com/X4u3yOW.png') 
            em.set_thumbnail(url='https://i.imgur.com/f05uKPn.png')  
            await ctx.send(embed = em)

我可能需要这一行代码的帮助:

         em.add_field(name = 'LOJINHA 2.0 ',value = int(result1[3])

我得到这个错误:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: tuple index out of range

^CMarcoss-Air:economia CIP$
Marcoss-Air:economia CIP$


Tags: nameinpyaddidcursorextcommands

热门问题