conn = sqlite3.connect("Discord.db") # или :memory:
cursor = conn.cursor()
@client.event
async def on_ready():
cursor.execute("""CREATE TABLE if NOT EXISTS (
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl 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)")
else:
pass
connect.commit()
print('Bot connect')
@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}, 0, 0, 1)")
conn.commit()
else:
pass
@client.command(aliases = ['balance', 'cash'] )
async def __balance(ctx , member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed (
description = f"""Баланс пользователя **{ctx.author}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]} :leaves:**"""
))
else:
await ctx.send(embed = discord.Embed (
description = F"""Баланс пользователя **{member}** составляет **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(member.id)).fetchone()[0]} :leaves:"""
))