import discord
from discord.ext import commands
import sqlite3
from config import settings
bot = commands.Bot(command_prefix = settings["prefix"])
bot.remove_command("Help")
connection = sqlite3.connect("server.db")
cursor = connection.cursor()
client = commands.Bot(command_prefix="!")
@client.event
async def on_ready():
cursor.execute(""" CREATE TABLE IF NOT EXISTS users (
country TEXT,
id INT,
money BIGINT,
science BIGINT,
water BIGINT,
eat BIGINT,
energy BIGINT,
titan BIGINT,
aluminium BIGINT,
tritium BIGINT,
intelligence BIGINT,
vote BIGINT
)""")
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}, 350, 100, 15, 45, 30, 10, 10, 10, 0, 40)")
connection.commit()
else:
pass
connection.commit()
print("Bot connected")
@client.event
async def on_member_join(member):
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}, 350, 100, 15, 45, 30, 10, 10, 10, 0, 40")
connection.commit()
else:
pass
@client.command(aliases =["Resources"])
async def balance(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
description = f"""Ресурсы:\rДеньги:{cursor.execute("SELECT money FROM users WHERE id = {}").format(ctx.author.id)}\rНаука:{cursor.execute("SELECT science FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rВода:{cursor.execute("SELECT water FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rЕда:{cursor.execute("SELECT eat FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rЭнергия:{cursor.execute("SELECT energy FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rТитан:{cursor.execute("SELECT titan FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rАлюминий:{cursor.execute("SELECT aluminium FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rТритий:{cursor.execute("SELECT tritium FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rРазведданные:{cursor.execute("SELECT intelligence FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}\rГолоса:{cursor.execute("SELECT vote FROM users WHERE id = {}").format(ctx.author.id).fetcone()[0]}"""
))
else:
pass
client.run("TOKEN")