FunkyBot/__main__.py
2025-06-16 03:08:16 -05:00

62 lines
1.9 KiB
Python

import os
import asyncio
import discord
from libs.Db import Db
from libs.BotLog import BotLog
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")
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
async def on_ready(self):
print(f"Logged in as {self.user.name}")
# await self.cmd_tree.sync(guild=discord.Object(id=551671017823797248))
await self.load_cogs()
for cog in self.cogs:
print(f"{cog} Commands")
cg = self.get_cog(cog)
cmds = cg.get_commands()
print([f"/{c.name}" for c in cmds])
synced = await self.tree.sync(guild=discord.Object(id=guild_id))
print(synced)
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.start(token)
asyncio.run(main())