import discord
from discord.ext import commands
import sqlite3
from config import settings
bot = commands.Bot(command_prefix=settings['PREFIX'], intents=discord.Intents.all())
bot.remove_command('help')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
membernal = '1100866520097226943'
@bot.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT,
bank BIGINT,
exp BIGINT,
last_message_time REAL
)""")
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, 0, 1, 0, 0, 0)")
connection.commit()
print('Bot connected')
bot.run(settings['TOKEN'])
Ошибка была в том, что в таблицу users было передано 6 значений, а необходимо было передать 8, так как в таблице users 8 столбцов. Проблема была вызвана неправильным форматированием строки SQL запроса в строке 26:
cursor.execute(f"INSERT INTO users VALUES ('{member}', { member.id }, 0, 0, 1, 0)")
Необходимо было добавить значения для двух дополнительных столбцов warns и mute:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1, 0, 0, 0)")
2023-04-27 16:59:43 INFO discord.client logging in using static token
2023-04-27 16:59:46 INFO discord.gateway Shard ID None has connected to Gateway (Session ID: d87b2052b06fc74b05408ce014407e79).
2023-04-27 16:59:48 ERROR discord.client Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\ISL\PycharmProjects\BOTeconomik\venv\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "C:\Users\ISL\PycharmProjects\BOTeconomik\main.py", line 26, in on_ready
cursor.execute(f"INSERT INTO users VALUES ('{member}', { member.id }, 0, 0, 1, 0)")
sqlite3.OperationalError: table users has 8 columns but 6 values were supplied
вот отрывок кода о базе данных
mport discord
from discord.ext import commands
import sqlite3
from config import settings
bot = commands.Bot (command_prefix=settings['PREFIX'], intents=discord.Intents.all())
bot.remove_command('help')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
membernal = '1100866520097226943'
@bot.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users(
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT,
bank BIGINT
)""")
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, 0, 1, 0)")
connection.commit()
print('bot connected')