MinecraftStatus/src/mstbot/bot.py
Benjamin Morgan 9cb489b4d0
All checks were successful
Build & Deploy MSTBot / Build & push runner image (push) Successful in 34s
Build & Deploy MSTBot / Build, push & deploy (push) Successful in 1m16s
Build & Deploy MSTBot / Create release (push) Has been skipped
Major refactors
2026-10-04 21:41:29 -06:00

34 lines
1.5 KiB
Python

import discord
import socket
from mstbot.cogs.admin import Admin
from mstbot.cogs.other import Other
from mstbot.utils import safe_send, log
class MinecraftStatusBot(discord.ext.commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
super().__init__(command_prefix="$", intents=intents)
async def setup_hook(self):
await self.add_cog(Admin(self))
await self.add_cog(Other(self))
async def on_command_error(self, ctx: discord.ext.commands.Context, error: discord.ext.commands.CommandError):
command = ctx.message.content.split()[0][1:] # Extract command name
if isinstance(error, discord.ext.commands.CommandNotFound):
await safe_send(f'Command "{command}" does not exist. Use `{ctx.prefix}help` for available commands.', ctx)
elif isinstance(error, discord.ext.commands.MissingRequiredArgument):
await log(ctx, f'Command "{command}" is missing required arguments. Use `{ctx.prefix}help {command}` for details.')
elif isinstance(error, discord.ext.commands.MissingPermissions):
await safe_send(f'You lack permissions: {", ".join(error.missing_perms)}.', ctx)
elif isinstance(error, discord.ext.commands.CommandInvokeError) and isinstance(error.original, socket.gaierror):
await log(ctx, "Could not connect, is the server down?")
else:
raise error