ОШИБКА:
File "bot.py", line 324, in __buy
elif cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role.id)).fetchone()[0] > cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[1]:
IndexError: tuple index out of range
ТАБЛИЦА:
@client.event
async def on_ready():
print('SolaBot готов к полёту!')
await client.change_presence(status = discord.Status.online, activity = discord.Game('!help |alpha|'))
cursor.execute("""CREATE TABLE IF NOT EXISTS users(
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT,
server_id INT
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS shop(
role_id INT,
id INT,
cost BIGINT
)""")
for guild in client.guilds:
for member in guild.members:
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES('{member}', {member.id}, 0, 0, 1, {guild.id})")
else:
pass
conn.commit()
print('DataBase Loading... 100%')
КОД:
@client.command(aliases = ['buy'])
async def __buy(ctx, role: discord.Role = None):
if role is None:
await ctx.send(f"**{ctx.author}**, укажите роль которую желаете приобрести")
else:
if role in ctx.author.roles:
await ctx.send(f"**{ctx.author}**, у вас уже имеется данная роль")
elif cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role.id)).fetchone()[0] > cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[1]:
await ctx.send(f"**{ctx.author}**, у вас недостаточно средств для покупки данной роли")
else:
await ctx.author.add_roles(role)
cursor.execute("UPDATE users SET cash = cash - {0} WHERE id = {1}".format(cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role_id)).fetchone()[0], ctx.author.id))
await ctx.message.add_reaction('✅')