Ошибка IndexError: tuple index out of range
Пытался написать магазин для Discord Бота на Python и столкнулся с ошибкой "IndexError: tuple index out of range"
В бд уже есть несколько товаров
Вот код:
client = commands.Bot( command_prefix = '%')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
@client.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS shop (
who TEXT,
id INT,
cost BIGINT
) """)
@client.command(aliases = ['shop'])
async def __shop(ctx):
embed = discord.Embed(title='Shop', colour = discord.Color.green())
embed.set_footer(text = 'Request by {}'.format(ctx.author.name), icon_url = ctx.author.avatar_url)
for row in cursor.execute("SELECT id, cost FROM shop"):
embed.add_field(
name = f'Стоимость **{row[1]} :dollar:**',
value = f'Вы приобретете {cursor.execute("SELECT who FROM shop")}',
inline = False
)
await ctx.send(embed = embed)
Вот текст ошибки:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: IndexError: tuple index out of range
Ответы (1 шт):
Автор решения: Master_Sniffer
→ Ссылка
Ошибка заключена в том, что вы выходите за пределы кортежа (tuple). Попробуйте вписать в цикл -1, чтобы он не выходил за пределы ( так как spisok1=(1,20,3) - для питона, чтобы получить 20 нужно написать print (spisok1[1]) )
Если остались вопросы - дайте знать