discord.py SQLite 获取行内容

discord.py SQLite getting row content

@client.command()
async def tag(ctx, tag):
    sql.execute(f'select tags_name from tags_list')
    does_exist = sql.fetchone()
    print(does_exist)

    if does_exist is not None:
        sql.execute(f'SELECT tags_content FROM tags_list')
        final = sql.fetchall()
        await ctx.send(final[0])
    else:
        await ctx.send(f"Tag named `{tag}` doesnt exists!")

所以您在上面看到的代码用于从 table tags_list.

获取内容

上面的图像是 table tags_list。我在调用命令时试图获得 tags_content 。但是例如,当我调用像 .tag test 这样的命令时,我希望它给我 test,因为它们在同一行。但相反,它给出了第一行的 tags_content 。所以它给出 h 而不是 test。如何指定要从中获取内容的行?

编辑:这是我在 运行 命令 .tag test 时得到的结果:('h',)

当您从 SQLite table 中选择一行时,您可以使用 WHERE 来指定您想要的行。例如:

SELECT tags_content FROM tags_list WHERE tags_name='test'

因此您可以在选择行时使用 tag 参数指定 tags_name

@client.command()
async def tag(ctx, tag):
    sql.execute(f'SELECT tags_content FROM tags_list where tags_name = "{tag}"')
    final = sql.fetchone()
    if final:
        await ctx.send(final)
    else:
        await ctx.send(f"Tag named `{tag}` doesnt exists!")