FunkyBot/__main__.py

72 lines
2.2 KiB
Python

import os
import asyncio
import discord
from discord import Client
from libs.Db import Db
from libs.BotLog import BotLog
from libs.Channels import Channel
from libs.Guilds import Guilds
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
token = os.getenv("DISCORD_TOKEN")
prefix = os.getenv("COMMAND_PREFIX")
guild_id = os.getenv("GUILD_ID")
dev_mode = os.getenv("DEV_MODE")
bot_intents = discord.Intents.default()
bot_intents.message_content = True
bot_intents.members = True
class FunkyBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=prefix,
intents=bot_intents
)
self.log_handler = BotLog("bot.log")
self.db = Db('sqlite:///data/bot.db', True)
self.guild_id = guild_id
self.dev_mode = dev_mode == "1"
async def on_ready(self):
print(f"Logged in as {self.user.name}")
guild = discord.Object(id=guild_id)
synced = await self.tree.sync(guild=guild)
print(synced)
async def async_cleanup(self):
guild = await Guilds().get_guild(self)
channel = await Channel().get_channel(guild, "add-roles")
await channel.purge()
await channel.send("FunkyBot is currently sleeping. Please try again once he has awakened.")
async def close(self):
await self.async_cleanup()
await super().close()
async def on_member_join(self, member):
channel = discord.utils.get(member.guild.channels, name="general")
role = discord.utils.get(await member.guild.fetch_roles(), name="Chinstrap Penguins")
if role is not None:
if role not in member.roles:
await member.add_roles(role)
await channel.send(f"Another Penguin has joined the Collective. Everyone say hi to {member.mention}!")
async def load_cogs(self):
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
await self.load_extension(f"cogs.{filename[:-3]}")
print(f"Loaded {filename[:-3]}")
async def main():
bot = FunkyBot()
async with bot:
await bot.load_cogs()
await bot.start(token)
asyncio.run(main())