-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
58 lines (47 loc) · 2.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import discord
import sqlite3
from discord.ext import commands
from config import *
# Создание intents для работы с намерениями
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=settings['prefix'], intents=intents)
data_base = sqlite3.connect('bot_test.db', timeout=10)
cursor = data_base.cursor()
@bot.event
async def on_ready():
print('Bot launched successfully :)')
print(f'My name is {bot.user.name}')
print(f'My client id is {bot.user.id}')
for guild in bot.guilds:
print(f'Connected to server, id is: {guild.id}')
for member in guild.members:
cursor.execute(f"SELECT id FROM users where id={member.id}")
if cursor.fetchone() is None:
cursor.execute(
f"INSERT INTO users VALUES ({member.id}, '{member.name}', '<@{member.id}>', 0)")
else:
pass
data_base.commit()
@bot.command()
async def balance(ctx):
for row in cursor.execute(f"SELECT nickname, money FROM users where id={ctx.author.id}"):
embed = discord.Embed(title=f'Аккаунт пользователя {row[0]}', color=0x42f566)
embed.add_field(name='Баланс:', value=f'{row[1]} SH', inline=False)
await ctx.send(embed=embed)
async def give_money(ctx, mention, money):
try:
mention = str(mention).replace('!', '')
for row in cursor.execute(f'SELECT money FROM users where mention=?', (mention,)):
cursor.execute(f'UPDATE users SET money={int(money) + row[0]} where mention=?', (mention,))
data_base.commit()
for row in cursor.execute(f'SELECT nickname FROM users where mention=?', (mention,)):
embed = discord.Embed(title='Пополнение баланса', color=0x42f566)
embed.set_author(name='Community Bot')
embed.add_field(name='Оповещение', value=f'Баланс пользователя {row[0]} пополнен на {money} SH')
await ctx.send(embed=embed)
except Exception as E:
print(f'give_money command error: {E}')
embed = discord.Embed(title='Оповещение', color=0xFF0000)
embed.add_field(name='Оповещение', value='Ошибка при выполнение программы.')
await ctx.send(embed=embed)
bot.run(settings['token'])