P
P
Pavel Tortikov2020-07-15 04:39:07
Python
Pavel Tortikov, 2020-07-15 04:39:07

How to fix this error when launching a discord bot?

I run the bot and I see this error

spoiler
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\Паша\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py"
, line 312, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Паша\Desktop\Bot\bot.py", line 16, in on_ready
cursor.execute("""CREATE TABLE user (
sqlite3.OperationalError: near ")": syntax error

There was no error before. I tried to delete the part after which the error came out, nothing has changed
Here is the code itself
:
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('users.db')
cursor = connection.cursor()


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


client.run(Settings['TOKEN'])

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Taruu, 2020-07-21
@Cvenzi1

import discord
from discord.ext import commands

import sqlite3

client = commands.Bot(command_prefix = "!")
client.remove_command('help')
connection = sqlite3.connect('users.db')
cursor = connection.cursor()


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


client.run()

B
benders, 2020-08-28
@benders

lvl INTremove the comma after

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question