Answer the question
In order to leave comments, you need to log in
After adding SQLite3 to the code, the bot commands (discord py) stopped working, how to fix it?
I wanted to make a level system in the bot, but after adding SQLite3, the commands stopped working, what could be the reason for this?
import discord
from discord.ext import commands
import discord.utils
import time
import sqlite3
connection = sqlite3.connect('levels.db')
cursor = connection.cursor()
PREFIX = 'der '
TOKEN = 'token'
bot = commands.Bot(command_prefix=PREFIX)
bot.remove_command ('help')
auto_role_id = 748263618294054954
@bot.event
async def on_ready():
print("Ready!")
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
lvl INT,
messages BIGINT
)""")
connection.commit()
for guild in bot.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 )")
else:
pass
connection.commit()
@bot.event
async def on_member_ban(guild, member):
channel = guild.system_channel
emb = discord.Embed(title = 'Бан', colour = 0x2e2d2d)
emb.add_field(name = f"{member.name}#{member.discriminator}", value = f"был забанен(а)")
await channel.send(embed = emb)
print("Успешно")
@bot.event
async def on_member_unban(guild, member):
channel = guild.system_channel
emb = discord.Embed(title = 'Разбан', colour = 0x2e2d2d)
emb.add_field(name = f"{member.name}#{member.discriminator}", value = f"был разбанен(а)")
await channel.send(embed = emb)
print("Успешно")
@bot.event
async def on_member_remove(member):
channel = member.guild.system_channel
emb = discord.Embed(title = 'Выход', colour = 0x2e2d2d)
emb.add_field(name = f"{member.name}#{member.discriminator}", value = f"вышел из сервера")
await channel.send(embed = emb)
print("Успешно")
@bot.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 user VALUES ('{member}', {member.id}, 0, 0 )")
connection.commit()
else:
pass
channel = member.guild.system_channel
emb = discord.Embed(title = 'Вход',colour = 0x2e2d2d)
emb.add_field(name = f"{member.name}#{member.discriminator}", value = f"зашел на сервер")
role = discord.utils.get(member.guild.roles, id = 748263618294054954)
await member.add_roles(role, reason=None)
await channel.send(embed = emb)
print("Успешно")
@bot.event
async def on_message(message):
cursor.execute(f"UPDATE users SET messages = messages + 1 WHERE id = {message.author.id}")
connection.commit()
if cursor.execute(f"SELECT messages FROM users") == 10:
cursor.execute(f"UPDATE users SET lvl = lvl + 1 WHERE id = {message.author.id}")
connection.commit()
print("Успешно")
if cursor.execute(f"SELECT messages FROM users") == 50:
cursor.execute(f"UPDATE users SET lvl = lvl + 1 WHERE id = {message.author.id}")
connection.commit()
print("Успешно")
if cursor.execute(f"SELECT messages FROM users") == 100:
cursor.execute(f"UPDATE users SET lvl = lvl + 1 WHERE id = {message.author.id}")
connection.commit()
print("Успешно")
if cursor.execute(f"SELECT messages FROM users") == 150:
cursor.execute(f"UPDATE users SET lvl = lvl + 1 WHERE id = {message.author.id}")
connection.commit()
print("Успешно")
@bot.event
async def on_message_delete(message):
channel = message.guild.system_channel
authtor_name = message.author.name
authtor_tag = message.author.discriminator
content = message.content
emb = discord.Embed(title = 'Сообщение удалено', colour = 0x2e2d2d)
emb.add_field(name = f"Автор: {authtor_name}#{authtor_tag}", value = f"**Сообщение:** {content}")
await channel.send(embed = emb)
print("Успешно")
@bot.event
async def on_message_edit(before, after):
channel = before.guild.system_channel
authtor_name = before.author.name
authtor_tag = before.author.discriminator
content_old = before.content
content_new = after.content
emb = discord.Embed(title = 'Сообщение изменено', colour = 0x2e2d2d)
if before.author.name == 'der Roboter' and before.author.discriminator == '0044' and after.author.name == 'der Roboter' and after.author.discriminator == '0044':
pass
else:
emb.add_field(name = f"Автор: {authtor_name}#{authtor_tag}", value = f"До изменения: {content_old}\nПосле изменения: {content_new}")
await channel.send(embed = emb)
print("Успешно")
@bot.command(pass_context = True)
async def help(ctx, arg = None):
emb = discord.Embed(title = 'Помощь', colour = 0x2e2d2d)
if arg == 'poll':
emb.add_field(name = f"{ctx.prefix}poll", value = f"Использовать:\nder poll (название голосования), (первый параметр), (второй параметр), (и так до 9 раз)\nПример создания голосования:\npoll test, 1, 2")
await ctx.send(embed = emb)
print("Успешно")
elif arg == 'mute':
emb.add_field(name = f'{ctx.prefix}mute', value = f'Использовать:\nder mute [Упоминание пользователя] (Время мута в секундах(если не указано, мут на всегда даётся))\nПример:\nder mute @banana#0228 120')
await ctx.send(embed = emb)
print("Успешно")
elif arg == 'ban':
emb.add_field(name = f'{ctx.prefix}ban', value = f'Использовать:\nder ban [Упоминание пользователя]\nПример:\nder ban @banan#0228')
await ctx.send(embed = emb)
print("Успешно")
elif arg == None:
emb.add_field(name = f"{ctx.prefix}poll", value = f"Создание голосовния.")
emb.add_field(name = f"{ctx.prefix}ban", value = f"Бан участника.")
emb.add_field(name = f"{ctx.prefix}mute", value = f"Мут участника.")
await ctx.send(embed = emb)
print("Успешно")
@bot.command(pass_context = True)
async def poll(ctx):
emb = discord.Embed(title = 'Голосование', colour = 0x2e2d2d)
emb.add_field(name = f'', value = f'')
@bot.command (pass_context = True)
@commands.has_permissions(ban_members = True)
async def ban(ctx, member: discord.Member, reason = None):
await member.ban ( reason = reason )
print("Успешно")
@bot.command(pass_context = True)
@commands.has_permissions(manage_roles = True)
async def mute(ctx, member: discord.Member, arg = None):
mute_role = discord.utils.get(member.guild.roles, id = 748864395374755921)
if arg == None:
await member.add_roles(mute_role, reason = 'Нарушил правило.')
print("Успешно")
else:
await member.add_roles(mute_role, reason = 'Нарушил правило.')
arg = int(arg)
time.sleep(arg)
await member.remove_roles(mute_role, reason = 'Время прошло.')
print("Успешно")
@bot.command(pass_context = True, aliases = ['lvl', 'level'])
async def __lvl(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
description = f"""Уровень пользователя **{ctx.author}** равен {cursor.execute(f"SELECT lvl FROM users WHERE id = {ctx.author.id}").fetchone()[0]}"""
))
connection.commit()
print("Успешно")
else:
await ctx.send(embed = discord.Embed(
description = f"""Уровень пользователя **{member} равен {cursor.execute(f"SELECT lvl FROM users WHERE id = {member.id}").fetchone()[0]}"""
))
connection.commit()
print("Успешно")
bot.run(TOKEN)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question