Files
SSCBot
Code
43 6,726
SSCBot/bot.py
"""Six Songs Contest Discord Bot - Main Entry Point"""
import discord
from discord.ext import commands
import os
import json
from dotenv import load_dotenv
load_dotenv()
class SSCBot(commands.Bot):
"""Main bot class for Six Songs Contest"""
def __init__(self):
intents = discord.Intents.all()
super().__init__(
command_prefix=commands.when_mentioned_or('!'),
intents=intents,
help_command=None,
activity=discord.Activity(
type=discord.ActivityType.listening,
name='🎵 Six Songs Contest'
)
)
self.config = self.load_config()
def load_config(self):
config_path = 'config.json'
if os.path.exists(config_path):
with open(config_path) as f:
return json.load(f)
return {}
async def setup_hook(self):
"""Load all cogs"""
cogs_dir = 'cogs'
for filename in os.listdir(cogs_dir):
if filename.endswith('.py') and not filename.startswith('__'):
try:
await self.load_extension(f'cogs.{filename[:-3]}')
print(f'✓ Loaded cog: {filename[:-3]}')
except Exception as e:
print(f'✗ Failed to load {filename}: {e}')
async def on_ready(self):
print(f'✓ {self.user} is ready!')
print(f' Servers: {len(self.guilds)}')
print(f' Users: {sum(g.member_count for g in self.guilds)}')
async def on_command_error(self, ctx, error):
"""Global error handler"""
if isinstance(error, commands.CommandNotFound):
return
if isinstance(error, commands.MissingPermissions):
await ctx.send('❌ You don\'t have permission to use this command.')
return
if isinstance(error, commands.BotMissingPermissions):
await ctx.send('❌ I don\'t have the required permissions.')
return
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f'⏰ Command on cooldown. Try again in {error.retry_after:.0f}s.')
return
print(f'Error: {error}')
await ctx.send(f'❌ An error occurred: {str(error)[:200]}')
if __name__ == '__main__':
bot = SSCBot()
token = os.getenv('DISCORD_TOKEN')
if token:
bot.run(token)
else:
print('❌ No DISCORD_TOKEN found in .env file')