Major refactors
This commit is contained in:
parent
00e2bd5ee3
commit
9cb489b4d0
13 changed files with 746 additions and 679 deletions
34
src/mstbot/bot.py
Normal file
34
src/mstbot/bot.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue