L
L
lolSaByR2020-12-17 14:10:03
Python
lolSaByR, 2020-12-17 14:10:03

How to fix error in discord.py?

I made an economic bot for Discord in Python. I wrote the code, I run the bot, and I get the error

"Ignoring exception in on_ready
Traceback (most recent call last):
File "/home/sabyr/.local/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "/home/sabyr/python/main.py", line 26, in on_ready
if cursor.execute(f"SELECT id FROM user WHERE id = {member. id}").fetchone() is None:
sqlite3.OperationalError: no such table: user".

Please help me to solve this error.

import discord
from discord.ext import commands

import sqlite3
from config import settings

client = commands.Bot(command_prefix = settings['PREFIX'])
client.remove_command('help')

connection = sqlite3.connect('server.db')
cursor = connection.cursor()


@client.event
async def on_ready():
    cursor.execute("""CREATE TABLE IF NOT EXISTS users (
        name TEXT,
        id INT,
        cash BIGINT,
        rep INT,
        lvl INT
    )""")

    for guild in client.guilds:
        for member in guild.members:
            if cursor.execute(f"SELECT id FROM user WHERE id = {member.id}").fetchone() is None:
                cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
            else:
                pass

    connection.commit()
    print('Bot connected')


@client.event
async def on_member_join(member):
    if cursor.execute(f"SELECT id FROM user WHERE id = {member.id}").fetchone() is None:
        cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
        connection.commit()
    else:
        pass


@client.command(aliases = ['balance', 'cash'])
async def __balance(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]} :leaves:**"""
        ))
    else:
        await ctx.send(embed = discord.Embed(
            description = f"""Баланс пользователя **{member}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(member.id)).fetchone()[0]} :leaves:**"""
        ))


client.run(settings['TOKEN'])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Melnikov, 2020-12-17
@Mi11er

you have an error in the table name
Create Users
Request in User
ps The error screams about this

no such table: user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question