iamkubi / pydactyl

Python wrapper for the Pterodactyl Panel API
MIT License
67 stars 21 forks source link

Creating database in server is going wrong #87

Closed Poseidon281 closed 5 months ago

Poseidon281 commented 5 months ago

Describe the bug I get a error when trying to create a database with this function

To Reproduce Steps to reproduce the behavior. Please make sure to include sample code that will reproduce your issue. If applicable include the full traceback, not just a single line error message. Code:

import discord
from discord.ext import commands
from pydactyl import PterodactylClient
from python_json_config import ConfigBuilder

builder = ConfigBuilder()
config = builder.parse_config('bot/config.json')

LINK = config.pterodactyl_link
API_KEY = config.pterodactyl_API_KEY
ID = config.GUILD_ID

api = PterodactylClient(LINK, API_KEY)

class Database(commands.Cog):
    def __init__(self, bot: commands.Bot):
        self.bot = bot

    @commands.command()
    async def database(self, ctx):
        view = Database.DatabaseView(bot=self.bot)
        await ctx.send("Select a database action:", view=view)

    class DatabaseView(discord.ui.View):
        def __init__(self, bot: commands.Bot):
            super().__init__()
            self.bot = bot

        @discord.ui.select(
            placeholder="What database action do you want to take?",
            min_values=1,
            max_values=1,
            options=[
                discord.SelectOption(
                    label="Create a Database",
                    description="Create a database in a specific server"
                ),
                discord.SelectOption(
                    label="Delete a database",
                    description="Delete a database in a specific server"
                ),
                discord.SelectOption(
                    label="Get information about a database",
                    description="Retrieve all information about a specific database"
                )
            ]
        )
        async def select_callback(self, select, interaction):
            if select.values[0] == "Create a Database":
                modal = Database.Modal_Create_DB(title="Creating Database....")
                await interaction.response.send_modal(modal)
            elif select.values[0] == "Delete a database":
                await interaction.response.send_message("Deleting a database...")
            elif select.values[0] == "Get information about a database":
                await interaction.response.send_message("Getting database information...")
            else:
                await interaction.response.send_message("Invalid selection!")

    class Modal_Create_DB(discord.ui.Modal):
        def __init__(self, *args, **kwargs) -> None:
            super().__init__(*args, **kwargs)

            self.add_item(discord.ui.InputText(label="Server ID"))
            self.add_item(discord.ui.InputText(label="Database Name"))

async def callback(self, interaction: discord.Interaction):
    try:
        server_id = self.children[0].value
        database_name = self.children[1].value
        api.servers.create_server_database(server_id, database_name)
        embed = discord.Embed(title="Result:")
        embed.add_field(name="Database Name", value=database_name)
        embed.add_field(name="Server ID", value=server_id)
        await interaction.response.send_message(embeds=[embed])
    except Exception as e:
        embed = discord.Embed(title="Result:")
        embed.add_field(name="Error", value=str(e))
        embed.add_field(name="Server ID", value=server_id)
        embed.add_field(name="Database Name", value=database_name)
        await interaction.response.send_message(embeds=[embed])

def setup(bot: commands.Bot):
    bot.add_cog(Database(bot))

Expected behavior A clear and concise description of what you expected to happen.: The expected output is that a Database is created

Environment

Additional context Add any other context about the problem here.

Output: Schermafbeelding 2024-04-10 162032

iamkubi commented 5 months ago

The error tells you exactly what you're missing.

Poseidon281 commented 5 months ago

The error tells you exactly what you're missing.

Yes it does, but i the server ID is right there and so is the name. And in the documentation it only says i need a Server-ID

iamkubi commented 5 months ago

You've only provided 2 of the 3 things it requires. The parameter list in the documentation is accurate, although the docstring doesn't list one of the parameters.

Poseidon281 commented 5 months ago

You've only provided 2 of the 3 things it requires. The parameter list in the documentation is accurate, although the docstring doesn't list one of the parameters.

Oke but what is the remote connection string. It can be % right?