JuicyBot_Base/index.py

61 lines
2.0 KiB
Python

import discord
from discord.ext import commands
import sqlite3
import configloader
import random
import logging
from logging.handlers import RotatingFileHandler
logger = logging.getLogger('discord')
logger.setLevel(logging.WARNING)
handler = RotatingFileHandler(filename='logs/bot.log', maxBytes=1024 * 5, backupCount=2, encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
__version__ = '0.0.1'
bot = commands.Bot(command_prefix=configloader.__prefix__)
def Database(db):
with sqlite3.connect(db) as con:
c = con.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS `users` (`name`,`id`, `platform`);''')
con.commit()
c.close()
@bot.event
async def on_ready():
bot_app_info = await bot.application_info()
print("------------------------------------")
print(f"Owner: {bot_app_info.owner}")
print(f"Bot-Name: {bot.user.name}")
print(f"Bot-ID: {bot.user.id}")
print(f"Bot Version: {__version__}")
print("------------------------------------")
for cog in configloader.__cogs__:
try:
bot.load_extension(cog)
print(f"{cog} loaded")
except Exception as err:
print(f"Couldn't load cog: {cog}")
raise err
Database("db/db.db")
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Juicy developing."))
@bot.event
async def on_member_join(member):
bot_app_info = await bot.application_info()
emoji = [':wink:', ':wave:', ':tada:']
channel = bot.get_channel(int(configloader.__greet_channel__))
guild = member.guild
embed = configloader.embed.messageEmbed(f"Willkommen bei {guild.name} {random.choice(emoji)}",
f"{member.mention}",
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
await channel.send(embed=embed)
if __name__ == "__main__":
bot.run(configloader.__token__)