import disnake
import sqlite3
from disnake.ext import commands
client = commands.Bot(command_prefix = commands.when_mentioned_or('#'), intents = disnake.Intents.all())
connection = sqlite3.connect('server.sqbro')
cursor = connection.cursor()
class level_command(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
cursor.execute("""CREATE TABLE IF NOT EXISTS users(
name TEXT,
cash BIGINT,
lvl INT,
rep INT,
id INT,
server_id 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, {guild.id})")
else:
pass
connection.commit()
print('Ког level_command запущен!')
@commands.Cog.listener()
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, {guild.id})")
connection.commit()
else:
pass
@commands.command()
async def rank(self, ctx):
embed = disnake.Embed(colour = 0x2F3136)
embed.set_author(name = ctx.author, icon_url = ctx.author.avatar)
embed.add_field(name = 'Уровень', value = f"""**{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]}**""")
await ctx.reply(embed = embed)
def setup(bot):
bot.add_cog(level_command(bot))