import discord
from discord.ext import commands
from discord import context_managers
import sqlite3
from config import settings
client = commands.Bot(command_prefix='!',intents = discord.Intents.all(), test_guilds=[1131257354416029856])
client.remove_command('help')
connection=sqlite3.connect('discord.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,
lvl INT
)''')
connection.commit()
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)")
connection.commit()
else:
pass
print('bot connected')
@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)")
connection.commit()
else:
pass
@client.command()
async def hi(ctx):
print(hi)
@client.slash_command(aliases =['balance','cash'])
async def _balance(ctx,member: discord.Member=None):
if member is None:
await сtx.send(embed=discord.Embed(
description=f"""Баланс пользователя **{ctx.author}** составляет **{cursor.execute('SELECT cash FROM users WHERE id ={}'.format(ctx.author.id)).fetchone()[0]}:catcoin:**"""
))
else:
description = f"""Баланс пользователя **{member.id}** составляет **{cursor.execute('SELECT cash FROM users WHERE id ={}'.format(member.id)).fetchone()[0]}:catcoin:**"""
print('done')
@client.event
async def on_message(message):
print('1111')
client.run(settings['TOKEN'])
pycharm ругается на ctx