Answer the question
In order to leave comments, you need to log in
I create a bot on Discord.py + SQLite3. What is wrong here?
Here is the usual code:
# -*- coding: utf-8 -*-
import discord
from discord.ext import commands
import random
import asyncio
from asyncio import sleep
from discord_components import DiscordComponents, Button, ButtonStyle
from random import choice
import datetime
import re
import sqlite3
client = discord.ext.commands.Bot( command_prefix = '|', case_insensitive=True, intents = discord.Intents.all())
client.remove_command('help')
determine_flip = [1, 0]
datetime.datetime.utcnow()
# ЭКОНОМИКА, ЧУВАК!
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
)""")
connection.commit()
print('РАБОТАЕТ УХААХАХАХ')
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 VANUES ('{member}', {member.id}, 0, 0, 0)")
connection.commit()
else:
pass
@client.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 VANUES ('{member}', {member.id}, 0, 0, 0)")
else:
pass
@client.command(aliases= ['баланс', 'бал', 'балик'])
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]}` :cash:"""
))
else:
await ctx.send(embed=discord.Embed(
description=f"""Баланс пользователя **{member}** составляет `{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.member.id)).fetchone()[0]}` :cash:"""
))
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: OperationalError: no such column: cash
Answer the question
In order to leave comments, you need to log in
1. well, translate the text of the error, there is no cash field in the table
2.
f"""Баланс пользователя **{member}** составляет `{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.member.id)).fetchone()[0]}` :cash:"""
I see this with many, where do they teach shit like that?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question