Я создал бота для дискорда на языке python и хочу чтобы он мог показывать баланс пользователя. Вот код:
import discord
import sqlite3
from discord.ext import commands
connection = sqlite3.connect("Discord.db")
cursor = connection.cursor()
token = ''
bot = commands.Bot(command_prefix='+')
@bot.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS "users" (
"name" TEXT,
"id" INT,
"cash" BIGINT,
"rep" INT
)""")
connection.commit()
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, 100, 0")
connection.commit()
else:
pass
@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")
connection.commit()
else:
pass
@bot.command(aliases = ['balance','bal','money'])
async def bank(ctx,member: discord.Member = None):
if member is None:
await ctx.send(embed=discord.Embed(
description = f"""Баланс пользователя **{ctx.author}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}").format(ctx.author.id).fetchone()[0]}**"""
))
else:
await ctx.send(embed=discord.Embed(
description = f"""Баланс пользователя **{member}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}").format(member.id).fetchone()[0]}**"""
))
bot.run(token)
Запускаю бота и всё нормально ошибок нет, когда я пишу +bank чтобы посмотреть баланс не чего не происходит и в консоли выдаёт эту ошибку:
$ python bot.py
Ignoring exception in command bank:
Traceback (most recent call last):
File "C:\Users\xeon\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "bot.py", line 50, in bank
description = f"""Баланс пользователя **{ctx.author}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}").format(ctx.author.id).fetchone()[0]}**"""
sqlite3.OperationalError: unrecognized token: "{"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\xeon\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\xeon\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\xeon\AppData\Local\Programs\Python\Python38-32\lib\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: OperationalError: unrecognized token: "{"
Помогите пожалуйста!