F
F
firedemonyt2021-07-04 11:05:52
Python
firedemonyt, 2021-07-04 11:05:52

I'm writing a discord bot. While stopped on the database. This error pops up. Can you please help?

@bot.command()
async def status(ctx):
  base.execute("CREATE TABLE IF NOT EXISTS {}(userid INT, count INT)".format(ctx.message.guild.name))
  base.combit()
  waring = cur.execute('SELECT * FROM {} WHERE userid == ?'.format(ctx.message.guild.name)\
    ,(ctx.message.author.id,)).fetchone()
  if waring == None:
    await ctx.send(f'{ctx.message.author.mention}, у Вас нет предупреждений!')
  else:
    await ctx.send(f'{ctx.message.author.mention}, у Вас {waring[1]} предупреждений!')
#==============================================================================================
@bot.event
async def on_message(message):
  if {i.lower().translate(str.maketrans('','', string.punctuation)) for i in message.content.split(' ')}.\
  intersection(set(json.load(open('cens.json')))) != set():
    await message.channel.send(f'{message.author.mention}, тебе по губам надовать?')
    await message.delete()

    name = message.guild.name

    base.execute('CREATE TABLE IF NOT EXISTS {}(userid INT, count INT)'.format(name))
    base.combit()

    waring = cur.execute('SELECT * FROM {} WHERE userid == ?'.format(name),(message.author.id,)).fetchone()

    if waring == NONE:
      cur.execute('INSERT INTO {} VALUES(?, ?)'.format(name),(message.author.id,1))
      base.combit()
      await message.channel.send(f'{message.author.mention}, это первое предупреждение, за 3 - мут на 3 часа!')

    elif waring[1] == 1:
      cur.execute('UPDATE {} SET count == ? WHERE userid == ?'.format(name),(2,message.author.id))
      base.combit()
      await message.channel.send(f'{message.author.mention}, это второе предупреждение, за 3 - мут на 3 часа!')

    elif waring[2] == 2:
      cur.execute('UPDATE {} SET count == ? WHERE userid == ?'.format(name),(3,message.author.id))
      base.combit()
      await message.channel.send(f'{message.author.mention}, ТЫ ЗАМУЧЕН НА 3 ЧАСА! В СЛЕДУЮЩИЙ РАС СТАРАЙСЯ НЕ МАТЕРИТЬСЯ')
      await message.author.add_roles(rolemute)


here is the error: File "C:\Users\YARIK\Desktop\discordbot\bot.py", line 126, in status
base.execute("CREATE TABLE IF NOT EXISTS {}(userid INT, count INT)".format(ctx .message.guild.name))
sqlite3.OperationalError: near "BOTA": syntax error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-07-04
@sergey-gornostaev

Every week I write that you should not form queries by concatenation, interpolation and string formatting. Use prepared statements and you will be happy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question