from redbot.core import commands, Config class Pterodactyl(commands.Cog): """Pterodactyl allows you to manage your Pterodactyl Panel from Discord.""" def __init__(self, bot): self.bot = bot self.config = Config.get_conf(self, identifier=457581387213637448123567) self.config.register_guild( base_url="mc.bloom.host", api_key=None, server_id=None ) async def get_url(self, ctx, endpoint = None): """Returns the base url for the Servers API, or the url for a specific endpoint if one is provided.""" if not await self.config.guild(ctx.guild).server_id(): raise LookupError("Server ID not set.") elif not await self.config.guild(ctx.guild).base_url(): raise LookupError("Base URL not set.") base_url = await self.config.guild(ctx.guild).base_url() server_id = await self.config.guild(ctx.guild).server_id() url = f"https://{base_url}/api/client/servers/{server_id}/" if endpoint: url += endpoint return url @commands.command() async def test(self, ctx, endpoint = None): """This does stuff!""" try: if endpoint: url = await self.get_url(ctx, endpoint) else: url = await self.get_url(ctx) except LookupError as e: await ctx.send(f"Something went wrong.\n{e}") return await ctx.send(url)