R
R
redh34d2021-04-23 18:12:18
Python
redh34d, 2021-04-23 18:12:18

Python: where is the error in the code?

import discord
from discord.ext import commands

import sqlite3

bot = commands.Bot(command_prefix = "!")
bot.remove_command('help')

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

@ bot.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl 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, 0, 0)")
else:
pass

connection.commit()
print('Table created')

@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, 0, 0)")
connection.commit()
else:
pass

@bot.command(aliases = ['balance', 'coins'])
async def __balance(ctx, member: discord .Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
description = f"""User **{ctx.author}**'s balance is **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone() [0]}**"""
))
else:
await ctx.send(embed = discord.Embed(
description = f"""User **{member}**'s balance is **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(member.id)).fetchone()[0]}**"""
))

@bot.event
async def on_ready():
print("Bot is on the block!")

@bot.command()
async def say(ctx, arg):
await ctx.send(arg)

bot.run("TOKEN")

Error - discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such table: users

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexbprofit, 2021-04-23
@alexbprofit

There is no users table in the database

Q
qpyparty, 2021-04-23
@pyparty

There is no users table in the database
+ on which line is the error?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question