Не работает SQLite3 для дискорд бота
Всем привет! Пишу бота для дискорд сервера, вроде все настроил подключил базу данных Но выводит такую ошибку:
File "C:\Users\Admin\Desktop\LKSQ PROJECT\Дискорд Бот\LK CHAN.py", line 52, in on_message base.execute('CREATE TABLE IF NOT EXISTS {}(userid INT, count INT)'.format(name)) sqlite3.OperationalError: near "PROJECT": syntax error
Код прикладываю ниже:
import discord
import logging
from discord.ext import commands
import string
import json
import sqlite3
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='discordbot.log', encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
bot = commands.Bot(command_prefix="/", intents=discord.Intents.all())
bot.remove_command('help')
@bot.event
async def on_ready():
print('Бот {0.user} успешно запустился!'.format(bot))
global base, cur
base = sqlite3.connect('lkchan.db')
cur = base.cursor()
if base:
print("База данных бота успешно подключена")
@bot.event
async def on_member_join(member):
for ch in bot.get_guild(944684892485193778).channels:
if ch.name == "joined":
await bot.get_channel(959032082267521095).send(f'{member.mention}, hello!\nWelcome to LKSQ Project offcial discord server\nHave fun!')
@bot.event
async def on_member_remove(member):
for ch in bot.get_guild(944684892485193778).channels:
if ch.name == "leaved":
await bot.get_channel(959032112479084544).send(f'{member}\nHad left :(')
@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('cenz.json')))) != set():
await message.channel.send(f'{message.author.mention}, dont use curse words, please.')
await message.delete()
name = message.guild.name
base.execute('CREATE TABLE IF NOT EXISTS {}(userid INT, count INT)'.format(name))
base.commit()
warns = cur.execute('SELECT * FROM {} WHERE userid == ?'.format(name),(message.author.id,)).fetchone()
if warns == None:
cur.execute('INSERT INTO {} VALUES(?, ?)'.format(name),(message.author.id,1))
base.commit()
await message.channel.send(f'{message.author.mention},you got 1st warn! if you get 3 you will be muted!')
elif warns == 1:
cur.execute('UPDATE {} SET count == ? WHERE userid == ?'.format(name),(2,message.author.id))
base.commit()
await message.channel.send(f'{message.author.mention}, you got 2nd warn! if you get 3rd you will get muted!')
elif warns == 2:
cur.execute('UPDATE {} SET count == ? WHERE userid == ?'.format(name),(3,message.author.id))
base.commit()
await message.channel.send(f'{message.author.mention}, you got 3rd warn! You will get muted for violating rules\nBan will be ended in 6 hours!')
await message.author.set_role(945062359834185821)
await bot.process_commands(message)
@bot.command()
async def link(ctx):
author = ctx.message.author
await ctx.send(f'{author.mention}\nLinks:\nWMUP: https://drive.google.com/drive/folders/1Jeq9Cj0eovHgn0UBYKHthy-xs9Ld8pJW?usp=sharing\nMOSI: https://drive.google.com/drive/folders/1TIFPtfQSbAQALKC8wHp6dINmDjq2oKDa?usp=sharing')
@bot.command()
async def info(ctx, arg=None):
author = ctx.message.author
if arg == None:
await ctx.send(f'{author.mention}\nI am LK CHAN! How i can help you?\nTo help type: /info commands')
elif arg == 'commands':
await ctx.send(f'{author.mention}\n My commands:\n /link - links to our programs\n/gethelp - get help \n/info - show info about me\n/warnings - show your warns')
else:
await ctx.send(f'{author.mention}\n I dont understand you! Write correctly please.')
@bot.command()
async def gethelp(ctx):
author = ctx.message.author
await ctx.send(f'{author.mention}\n Get help here: https://docs.google.com/forms/d/e/1FAIpQLSd4BMPmjJlQ3QLvCWWBMhqy1tAfkFvp2b0e67IYg45yBUto-A/viewform')
bot.run('TOKEN')