implementing slash commands
This commit is contained in:
parent
43c69180c4
commit
44f4e56cdc
1 changed files with 13 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
from redbot.core import commands, Config
|
||||
import discord
|
||||
from redbot.core import commands, app_commands, Config
|
||||
|
||||
class Pterodactyl(commands.Cog):
|
||||
"""Pterodactyl allows you to manage your Pterodactyl Panel from Discord."""
|
||||
|
@ -12,28 +13,28 @@ class Pterodactyl(commands.Cog):
|
|||
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."""
|
||||
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.")
|
||||
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.")
|
||||
base_url = await self.config.guild(ctx.guild).base_url()
|
||||
server_id = await self.config.guild(ctx.guild).server_id()
|
||||
base_url = await self.config.guild(guild).base_url()
|
||||
server_id = await self.config.guild(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):
|
||||
@app_commands.command()
|
||||
async def test(self, interaction: discord.Interaction, endpoint: str = None):
|
||||
"""This does stuff!"""
|
||||
try:
|
||||
if endpoint:
|
||||
url = await self.get_url(ctx, endpoint)
|
||||
url = await self.get_url(interaction.guild, endpoint)
|
||||
else:
|
||||
url = await self.get_url(ctx)
|
||||
url = await self.get_url(interaction.guild)
|
||||
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
|
||||
await ctx.send(url)
|
||||
await interaction.response.send_message(url, ephemeral=True)
|
||||
|
|
Reference in a new issue