Answer the question
In order to leave comments, you need to log in
Discord sqlite3.OperationalError: near "m", where does this Error come from?
A friend wrote the code, half a year ago, and abandoned it, decided to change something, and then I get an error
---------------
Ignoring exception in on_ready
Traceback (most recent call last):
File " C:\Users\TANDER\AppData\Roaming\Python\Python39\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\TANDER\ Desktop\3\ShiroBot.py", line 56, in on_ready
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 52, 0, 0, 0, 0, {member. guild.id})")
sqlite3.OperationalError: near "m": syntax error
---------------
At the same time, the bot functions and the database works, but the bot does not respond to some people
Here piece of code:
import discord
from discord import Member
from discord.ext import commands
from discord.ext.commands import has_permissions, MissingPermissions
from discord.utils import get
import youtube_dl
import os
import random
import time
import json
import requests
import asyncio
import sqlite3
import config
from Cybernator import Paginator as pag
import psutil as ps
intents = discord.Intents.default()
intents.members = True
# Настройка бота
client = commands.Bot(command_prefix='ae', intents=intents)
client.remove_command('help')
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,
xp INT,
lvl INT,
warns BIGINT,
server_id INT
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS shop (
role_id INT,
id INT,
cost BIGINT,
des TEXT
)""")
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}, 52, 0, 0, 0, 0, {member.guild.id})")
else:
pass
connection.commit()
print("Бот в сети!")
while True:
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="Вас"))
#await client.change_presence(status=discord.Status.idle, activity=discord.Game('.help'))
#await bot.change_presence(activity=discord.Streaming(name="My Stream", url=my_twitch_url))
# Роль за вход и БД
@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}, 52, 0, 0, 0, 0, {member.guild.id})")
connection.commit()
else:
pass
channel = client.get_channel(452906561841397760) # ID канала
role = discord.utils.get(member.guild.roles, name="test") # ID роли
await member.add_roles(role)
emb = discord.Embed(description=f'Рад приветствовать тебя, {member.mention}! Добро пожаловать на наш сервер!', color=0x39d0d6)
emb.set_image(url='https://images-ext-1.discordapp.net/external/v-cVlr4w5UZw_Ux2c-Mg0QJ_IsvFXZMMxF6vrLWEN90/%3Fwidth%3D1440%26height%3D300/https/media.discordapp.net/attachments/787641066891378688/807032183364911135/momlvl.jpg?width=1433&height=299')
emb.set_footer(text='{}'.format(member.joined_at.strftime('%d.%m.%Y')), icon_url=member.avatar_url)
await channel.send(embed=emb)
Answer the question
In order to leave comments, you need to log in
This means that the name of that user contains quotes, as a result, with such text substitution, it is broken into pieces, causing a syntax error.
Use parameter passing instead of text formatting for queries
cursor.execute("INSERT INTO users VALUES (?, ?, 52, 0, 0, 0, 0, ?)", (member.name, member.id, member.guild.id))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question