Answer the question
In order to leave comments, you need to log in
SQLITE3 and Discord Python issue. How to decide?
I am programming my discord bot in python. Decided to do the economic part with SQLITE3. The problem is that with the $apples command, the number of apples (Currency in the bot) of the participant should be displayed, but SQLITE3 does not react to this command in any way and there is no error in the console. I also decided to try to print the value to the console, but also nothing, no errors, no response. Here is the problematic code (just in case, I’ll also attach the creation of the table):
#таблица sqlite3
connection = sqlite3.connect('hedgehog_bot.db')
cursor = connection.cursor()
@bot.event
async def on_ready():
DiscordComponents(bot)
#создание таблицы sqlite3 при запуске кода
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
cash BIGINT,
rep INT,
warns INT,
lvl INT,
salmon INT,
cod INT
)""")
connection.commit()
for guild in bot.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}, {100}, {0}, {0}, {0}, {0})")
else:
pass
connection.commit()
print("Бот готов!")
@bot.event
async def on_member_join(member):
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, 100, 0, 0, 0, 0)")
connection.commit()
else:
pass
...
#проблемная часть
@bot.command()
async def яблоки(ctx, *, member: discord.Member):
cash = cursor.execute(f"SELECT cash FROM users WHERE id = {member.id}").fetchone()[0]
print(cash)
await ctx.send(embed = discord.Embed(
description = f"""Баланс пользователя **{member.mention}** состовляет **{cursor.execute(f"SELECT cash FROM users WHERE id = {member.id}").fetchone()[0]}** """,
timestamp = ctx.message.created_at,
color = discord.Colour.from_rgb(255, 69, 0)
))
Answer the question
In order to leave comments, you need to log in
Try creating a separate apples variable.
@bot.command()
async def яблоки(ctx, *, member: discord.Member):
cash = cursor.execute(f"SELECT cash FROM users WHERE id = {member.id}").fetchone()[0]
print(cash)
apples = cursor.execute(f"SELECT cash FROM users WHERE id = {member.id}").fetchone()[0]
connection.commit()
await ctx.send(embed = discord.Embed(
description = f"""Баланс пользователя **{member.mention}** составляет **{apples}** """,
timestamp = ctx.message.created_at,
color = discord.Colour.from_rgb(255, 69, 0)
))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question