implementing slash commands

This commit is contained in:
Seaswimmer 2023-07-14 11:29:06 -04:00
parent 43c69180c4
commit 44f4e56cdc
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -1,4 +1,5 @@
from redbot.core import commands, Config import discord
from redbot.core import commands, app_commands, Config
class Pterodactyl(commands.Cog): class Pterodactyl(commands.Cog):
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord.""" """Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
@ -12,28 +13,28 @@ class Pterodactyl(commands.Cog):
server_id=None server_id=None
) )
async def get_url(self, ctx, endpoint = None): async def get_url(self, guild, endpoint = None):
"""Returns the base url for the Servers API, or the url for a specific endpoint if one is provided.""" """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(): if not await self.config.guild(guild).server_id():
raise LookupError("Server ID not set.") raise LookupError("Server ID not set.")
elif not await self.config.guild(ctx.guild).base_url(): elif not await self.config.guild(guild).base_url():
raise LookupError("Base URL not set.") raise LookupError("Base URL not set.")
base_url = await self.config.guild(ctx.guild).base_url() base_url = await self.config.guild(guild).base_url()
server_id = await self.config.guild(ctx.guild).server_id() server_id = await self.config.guild(guild).server_id()
url = f"https://{base_url}/api/client/servers/{server_id}/" url = f"https://{base_url}/api/client/servers/{server_id}/"
if endpoint: if endpoint:
url += endpoint url += endpoint
return url return url
@commands.command() @app_commands.command()
async def test(self, ctx, endpoint = None): async def test(self, interaction: discord.Interaction, endpoint: str = None):
"""This does stuff!""" """This does stuff!"""
try: try:
if endpoint: if endpoint:
url = await self.get_url(ctx, endpoint) url = await self.get_url(interaction.guild, endpoint)
else: else:
url = await self.get_url(ctx) url = await self.get_url(interaction.guild)
except LookupError as e: except LookupError as e:
await ctx.send(f"Something went wrong.\nError: `{e}`") await interaction.response.send_message(f"Something went wrong.\nError: `{e}`", ephemeral=True)
return return
await ctx.send(url) await interaction.response.send_message(url, ephemeral=True)