Files
cogs
utils
config.py
database.py
logger.py
main.py
README.md
requirements.txt
SETUP_INSTRUCTIONS.md
Code
51 5,743
main.py
import discord
from discord.ext import commands
import os
import asyncio
import logging
from dotenv import load_dotenv
from database import Database
from logger import setup_logger
import traceback
load_dotenv()
class ShakibStudioBot(commands.Bot):
def __init__(self):
intents = discord.Intents.all()
super().__init__(
command_prefix=commands.when_mentioned,
intents=intents,
help_command=None,
case_insensitive=True,
owner_id=None
)
self.logger = setup_logger()
self.db = Database()
self.support_server = "https://discord.gg/3mWFdcZXB7"
self.bot_name = "Shakib Studio Help"
async def setup_hook(self):
self.logger.info("Starting bot setup...")
await self.db.setup()
cogs_to_load = [
'cogs.help',
'cogs.moderation',
'cogs.security',
'cogs.verification',
'cogs.tickets',
'cogs.ai',
'cogs.utility',
'cogs.fun',
'cogs.economy',
'cogs.leveling',
'cogs.music',
'cogs.logging',
'cogs.automod',
'cogs.antinuke',
'cogs.antiraid',
'cogs.antispam',
'cogs.reactionroles',
'cogs.welcome',
'cogs.giveaways',
'cogs.polls',
'cogs.reminders',
'cogs.suggestions',
'cogs.afk',
'cogs.dm',
'cogs.embedbuilder',
'cogs.roles',
'cogs.channels',
'cogs.voice',
'cogs.backup',
'cogs.autorole',
'cogs.autoresponse',
'cogs.stats',
'cogs.info',
'cogs.invitetracker',
'cogs.transcript',
'cogs.setup',
'cogs.config',
'cogs.owner',
'cogs.developer',
]
for cog in cogs_to_load:
try:
await self.load_extension(cog)
self.logger.info(f"Loaded {cog}")
except Exception as e:
self.logger.error(f"Failed to load {cog}: {e}")
traceback.print_exc()
self.logger.info("Syncing slash commands...")
try:
synced = await self.tree.sync()
self.logger.info(f"Synced {len(synced)} command(s)")
except Exception as e:
self.logger.error(f"Failed to sync commands: {e}")
async def on_ready(self):
self.logger.info(f"Bot is online as {self.user} (ID: {self.user.id})")
self.logger.info(f"Connected to {len(self.guilds)} guilds")
self.logger.info(f"Loaded {len(self.cogs)} cogs")
# Count total commands
total_commands = sum(len(cog.get_app_commands()) for cog in self.cogs.values())
self.logger.info(f"Total commands loaded: {total_commands}")
activity = discord.Activity(
type=discord.ActivityType.watching,
name=f"/help | {len(self.guilds)} servers"
)
await self.change_presence(activity=activity, status=discord.Status.online)
self.logger.info("Bot is fully ready!")
print("\n" + "="*50)
print(f" {self.bot_name} is Online!")
print(f" Username: {self.user}")
print(f" User ID: {self.user.id}")
print(f" Servers: {len(self.guilds)}")
print(f" Commands: {total_commands}+")
print(f" Support: {self.support_server}")
print("="*50 + "\n")
async def on_guild_join(self, guild):
self.logger.info(f"Joined new guild: {guild.name} (ID: {guild.id})")
await self.db.add_guild(guild.id)
async def on_guild_remove(self, guild):
self.logger.info(f"Removed from guild: {guild.name} (ID: {guild.id})")
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandNotFound):
return
self.logger.error(f"Command error: {error}")
def main():
bot = ShakibStudioBot()
token = os.getenv('TOKEN')
if not token:
print("ERROR: No TOKEN found in environment variables!")
print("Please set TOKEN in your Replit Secrets or .env file")
return
try:
bot.run(token)
except discord.LoginFailure:
print("ERROR: Invalid TOKEN provided!")
except Exception as e:
print(f"ERROR: {e}")
traceback.print_exc()
if __name__ == "__main__":
main()