Build a Complete Advanced Discord Hosting Bot — Pearl Node
Act as a senior Python developer, Discord bot specialist, and Pterodactyl Panel API expert. Build a complete, production-ready Discord hosting bot for my hosting brand Pearl Node.
Do not give me only examples, snippets, pseudocode, or a basic demo. I need the complete working project with every required file and a beginner-friendly setup guide.
- Technology Stack
- Python 3.11+
- discord.py 2.x
- aiohttp for asynchronous Pterodactyl API requests
- aiosqlite for persistent SQLite storage
- python-dotenv for ".env" configuration
- Proper logging, error handling, type hints, and modular code
- Discord slash commands and prefix commands where appropriate
- Interactive Discord buttons, dropdowns, modals, and embeds
Use the official Pterodactyl Application API wherever possible. Do not use browser automation or direct database access to the Pterodactyl Panel.
- Brand and Appearance
The exact brand name is Pearl Node. Never spell it as Perl Node, Pearlnode Bot, or another incorrect variation in user-facing branding.
- Bot/project display name: Pearl Node
- Every bot embed footer must say: "Powered by Pearl Node"
- Use a clean, professional hosting-company design.
- Use consistent embed colours, clear status indicators, timestamps, and helpful error messages.
- Use emojis sparingly and professionally.
- Add a configurable bot presence/status.
- Include a professional ".help" command with categories, command descriptions, and usage examples.
- Do not hardcode a Discord server ID, user ID, Panel URL, API key, or other secret into the source code.
- Easy ".env" Configuration — Extremely Important
Make the configuration beginner-friendly. I should be able to control the bot primarily by editing ".env", without modifying Python files.
Create a complete ".env.example" containing documented settings for:
Discord configuration
- "DISCORD_BOT_TOKEN"
- "BOT_PREFIX"
- "BOT_OWNER_IDS"
- "ADMIN_ROLE_IDS"
- "LOG_CHANNEL_ID"
- "SUPPORT_CHANNEL_ID"
- "WELCOME_CHANNEL_ID"
- "BOT_STATUS"
- "TIMEZONE"
Allow multiple owner IDs and admin role IDs using comma-separated values.
Pterodactyl configuration
- "PANEL_URL"
- "PANEL_APPLICATION_API_KEY"
- "PANEL_CLIENT_URL"
- "PANEL_EMAIL_DOMAIN"
- "PANEL_PAGE_SIZE"
- "PANEL_API_TIMEOUT"
Normalize the Panel URL safely and remove trailing slashes. Never display API keys or passwords in Discord messages or logs.
Node selection — Make This Very Easy
I need a simple configuration system for selecting which Pterodactyl nodes the bot can use.
Support settings such as:
- "ALLOWED_NODE_IDS=1,2,3"
- "DEFAULT_NODE_ID=1"
- "NODE_SELECTION_MODE=dropdown"
- "ALLOW_USER_NODE_SELECTION=true"
- "SHOW_NODE_RESOURCE_INFO=true"
These are examples of configuration names, not assumptions about my actual Panel. You may improve the names, but document them clearly and implement them consistently.
Requirements:
- Read the allowed Node IDs from ".env".
- Fetch node information from the Pterodactyl Application API.
- Show only configured, allowed nodes in the user-facing dropdown.
- Validate every selected Node ID on the server side.
- Never trust a Node ID supplied directly by a user.
- If the default Node is not allowed or does not exist, handle it safely.
- If a configured Node is unavailable, report the issue clearly and offer another allowed Node if appropriate.
- If a Node has no available allocation, explain that the server cannot be created there.
- If the configured Node IDs are empty, fail safely with a helpful setup message instead of silently selecting an arbitrary Node.
- Add an admin command such as ".listnodes" to display allowed Nodes.
- Add ".panelcheck" to verify Panel connectivity and permissions.
- If resource usage is available through supported APIs, display it accurately. Do not pretend to know live free RAM, CPU, or storage when the API does not provide those values.
- Support an optional human-readable Node name mapping, such as "NODE_NAMES=1:Singapore,2:India,3:Germany", if implemented robustly.
- Support optional per-Node resource limits and availability settings.
- Explain how to obtain the correct Node IDs from the Panel.
Do not confuse a Pterodactyl Node ID with an Egg ID, Nest ID, server ID, or allocation ID. Keep these settings separate.
Account and hosting limits
Provide configurable settings for:
- "MAX_USERS"
- "MAX_SERVERS_PER_USER"
- "DEFAULT_SERVER_LIMIT"
- "MAX_SERVER_RAM_MB"
- "MAX_SERVER_DISK_MB"
- "MAX_SERVER_CPU"
- "DEFAULT_SERVER_RAM_MB"
- "DEFAULT_SERVER_DISK_MB"
- "DEFAULT_SERVER_CPU"
- "DEFAULT_SERVER_SWAP_MB"
- "DEFAULT_SERVER_IO"
- "DEFAULT_SERVER_DATABASES"
- "DEFAULT_SERVER_BACKUPS"
- "DEFAULT_SERVER_ALLOCATIONS"
- "MAX_CONCURRENT_CREATIONS"
- "COMMAND_COOLDOWN_SECONDS"
- "ACCOUNT_CREATION_ENABLED"
- "SERVER_CREATION_ENABLED"
- "USER_DELETION_ENABLED"
- "SERVER_DELETION_ENABLED"
Use clear units: RAM and disk in MB, CPU in the units expected by Pterodactyl, and timeouts in seconds. Explain the CPU allocation convention in the README.
Allow limits to be changed without editing Python source. Validate every resource request against configured limits and Panel constraints.
Never promise that ".env" resource limits create actual physical capacity. The Panel and VPS must have sufficient resources and valid allocations.
- Account Creation System
Create an interactive account registration workflow.
Suggested command: ".create user"
Features:
- Ask the user to confirm account creation.
- Enforce one bot-managed Panel account per Discord user by default.
- Enforce the configured maximum user count.
- Generate a safe, unique username.
- Generate a strong random password using a secure random generator.
- Generate the email using the configured domain, for example "username@example.com".
- Check for existing records and handle conflicts safely.
- Create the account through the Pterodactyl Application API.
- Save the Discord user ID and Panel user ID in SQLite.
- Show a clear success or failure embed.
- Deliver credentials privately through Discord DM where possible.
- Never publish passwords in a public channel.
- If DM delivery fails, do not post the password publicly; explain the safe next step.
- Never log passwords or API keys.
Important: Generating an email address with "PANEL_EMAIL_DOMAIN" does not create a mailbox or send a real email. Explain this clearly in the README.
- Server Creation System
Suggested command: ".create server"
Build a multi-step interactive server creation flow using Discord buttons, dropdowns, and modals.
User flow
- Verify that the user has a registered Panel account.
- Check whether server creation is enabled.
- Check the user's server limit.
- Display the allowed Nodes dropdown.
- Let the user select a supported server software/runtime.
- Display only compatible, configured options.
- Ask for a server name.
- Ask for the requested RAM, CPU, and disk within the configured limits.
- Show a confirmation embed with the selected Node, software, and resources.
- Create the server only after the user confirms.
- Display the result privately where possible.
- Save the server ownership and Panel server ID in SQLite.
Add a timeout to every interactive workflow. If a menu expires, show a useful message and allow the user to restart the command.
Supported server software
At minimum, support configurable options for:
- Node.js servers
- Python servers
Use a configurable software registry so additional software can be added later.
Egg, Nest, Docker image, and startup configuration
Make the configuration flexible enough to support different Pterodactyl Eggs.
For each software option, configure:
- Display name
- Nest ID
- Egg ID
- Compatible Node IDs, if needed
- Docker image or allowed image choices
- Startup configuration
- Default environment variables
- Required environment variables
- Allowed environment variables
- Default resource settings
Fetch and validate Egg information using the Panel API where possible. Respect the Egg's required variables, startup configuration, and Docker image requirements.
Do not assume all Eggs use the same environment variables. Do not blindly hardcode a Node.js or Python Egg ID.
Use only valid, administrator-configured Eggs and images. Never allow a user to submit an arbitrary Docker image or unrestricted startup command.
Environment variables for software profiles
Implement a clear, documented way to configure software profiles through ".env" or a separate configuration file such as "software_profiles.json".
Prefer a separate JSON file if that makes complex profiles easier to manage, while keeping all global settings and Node selection in ".env".
Include example profiles for Node.js and Python, clearly marked as examples that must be checked against the actual Panel.
Server creation safety
- Prevent duplicate server creation caused by double-clicks.
- Use database locks or another safe concurrency mechanism where necessary.
- Limit concurrent creation requests.
- Validate ownership and resource limits before every creation.
- Handle invalid Egg IDs, invalid Node IDs, unavailable allocations, API timeouts, and Panel errors gracefully.
- Do not claim a server was created until the API confirms success.
- Do not retry a creation blindly after an ambiguous timeout, because it could create duplicate servers.
- Save useful error details in logs without exposing secrets.
- Show the user a simple, non-sensitive explanation of the error.
- Server Management Commands
Implement commands such as:
- ".myservers" — show the user's bot-managed servers.
- ".serverinfo <server_id>" — show information only if the user owns the server or is authorized.
- ".serverstatus <server_id>" — display status only if supported by the available API.
- ".hostingstatus" — show a summary of the bot's hosting features and configured limits.
- ".panelcheck" — check Panel connectivity and required API permissions.
- ".listnodes" — list allowed Nodes.
- ".help" — display the help menu.
Use pagination for long lists. Do not expose private information belonging to another user.
Do not claim to provide live CPU/RAM usage or console controls unless the implementation uses the appropriate supported API.
- Safe Deletion System
Implement:
- ".deleteserver <server_id>"
- ".delete user"
Deletion must be restricted to authorized administrators by default, unless a separate, explicitly configured owner self-service policy is enabled.
Before deletion:
- Verify permissions.
- Show a confirmation prompt.
- Clearly explain which Panel object will be deleted.
- Require a second confirmation for destructive actions.
- Use the correct Pterodactyl API endpoint.
- Update the local database only after the API operation succeeds, or record a safe pending state when the result is uncertain.
- Log who requested the action and when, without storing credentials.
Never allow a normal user to delete another user's account or server. Never delete a whole Panel account when only a server deletion was requested.
If the Panel API cannot safely perform an action, explain the limitation instead of pretending the action succeeded.
- Admin Commands
Implement permission-protected admin commands:
- ".listusers"
- ".listnodes"
- ".panelcheck"
- ".hostingstatus"
- ".setlimit <user_id> <limit>" — optional per-user server limit override.
- ".userinfo <user_id>"
- ".reloadconfig" — reload supported configuration safely.
- ".syncusers" — optional reconciliation tool, if implemented safely.
- ".botstats"
Requirements:
- Verify the caller is a configured bot owner or authorized administrator.
- Do not trust the command prefix or a user's display name as proof of permission.
- Use pagination for large outputs.
- Keep sensitive data private.
- Never show passwords or API keys in admin lists.
- Validate user input and handle missing arguments.
Do not add an unsafe command that lets ordinary users execute arbitrary API requests or shell commands.
- Database and Reliability
Use SQLite through "aiosqlite".
Create the database and required tables automatically on startup. Include schema versioning or safe migrations.
Store, as needed:
- Discord user ID
- Panel user ID
- Username and non-sensitive account metadata
- Server ID
- Server owner Discord ID
- Node ID
- Software profile
- Creation timestamp
- User limit overrides
- Operation history and pending operation status
Do not store plaintext passwords or Panel API keys in SQLite.
Implement:
- Graceful shutdown
- API connection timeouts
- Safe error handling
- Retry only for operations that are safe to retry
- Rate limiting and cooldowns
- Audit logging
- Recovery from expired Discord interactions
- Duplicate operation prevention
- Useful startup validation
- Clear logs with secrets redacted
- Security Requirements
Security is essential.
- Use ".env" for secrets.
- Provide ".env.example" with placeholders only.
- Include ".env" in ".gitignore".
- Never print the bot token, Panel API key, or user passwords.
- Never commit real credentials.
- Validate permissions and all user inputs.
- Restrict allowed Nodes, Eggs, Docker images, and environment variables.
- Use least-privilege API keys where the Panel supports them.
- Avoid exposing internal exceptions to users.
- Use Discord DMs or ephemeral interactions for private information where supported.
- Never disable TLS certificate verification.
- Do not execute user-supplied shell commands.
- Prevent command abuse and resource exhaustion.
- Explain that the Discord bot should be run on a trusted machine or VPS.
- Suggested Project Structure
Create a complete modular project similar to:
"pearl-node-bot/"
- "main.py"
- "config.py"
- "requirements.txt"
- ".env.example"
- ".gitignore"
- "README.md"
- "software_profiles.json"
- "cogs/__init__.py"
- "cogs/account.py"
- "cogs/hosting.py"
- "cogs/deletion.py"
- "cogs/admin.py"
- "cogs/help.py"
- "utils/__init__.py"
- "utils/panel_api.py"
- "utils/database.py"
- "utils/security.py"
- "utils/views.py"
- "utils/embeds.py"
- "tests/"
- "data/" — created automatically; do not commit sensitive database contents.
You may improve this structure if needed, but keep the project understandable to a beginner.
- README.md — Complete Beginner Guide
Write a detailed "README.md" explaining:
- What Pearl Node does.
- Required Python version.
- How to create a Discord bot in the Discord Developer Portal.
- How to enable the required intents and invite the bot with appropriate permissions.
- How to create a Pterodactyl Application API key.
- How to set the Panel URL and API key.
- How to find Node, Nest, Egg, and allocation information.
- How to configure allowed Nodes in ".env".
- How to configure Node.js and Python software profiles.
- How to set account limits and resource limits.
- How to install dependencies on Ubuntu.
- How to configure ".env".
- How to start the bot.
- How to verify Panel connectivity.
- How to test account and server creation.
- How to troubleshoot common errors, including 401, 403, 404, 422, and 5xx API responses.
- How to run the bot with "systemd" on Ubuntu.
- How to inspect logs and restart the service.
- How to back up the SQLite database.
- How to rotate leaked API keys and bot tokens.
Use copy-ready commands and explain where to run each command. Do not assume that the reader is an experienced developer.
Do not include real API keys, tokens, passwords, or private server details in examples.
- Testing and Validation
Include automated tests for important logic, especially:
- ".env" configuration parsing.
- Comma-separated Node ID parsing.
- Rejecting unauthorized Node IDs.
- User permission checks.
- Server resource limit validation.
- Server ownership checks.
- Database initialization.
- Duplicate request prevention.
- Safe deletion confirmation.
- Handling Panel API errors.
Use mocked API responses for automated tests so the tests do not create real Panel accounts or servers.
If you can execute code, verify the project using:
- Python syntax/compilation checks.
- Dependency/import checks.
- Automated tests.
- A check that all referenced modules and files exist.
Clearly distinguish tests that passed from tests that require a real Discord bot or Pterodactyl Panel. Do not claim live integration has been tested unless it actually has.
- Final Deliverables
Provide:
- The complete source code for every required file.
- A complete "README.md".
- A complete ".env.example".
- A configurable software profiles example.
- Automated tests.
- A "requirements.txt".
- A ".gitignore".
- A ZIP archive of the entire project, if file creation is available.
- A clear beginner-friendly deployment guide.
Do not leave placeholder functions, incomplete files, missing imports, fake API methods, or TODOs for essential functionality.
If any feature cannot be fully implemented because of Pterodactyl API limitations or missing Panel information, explain the exact limitation and implement a safe alternative.
Do not invent successful test results. If a ZIP is generated, verify that it exists and contains the complete project.
Final objective: Deliver a secure, modular, professional, feature-rich Pearl Node Discord hosting bot that is easy to configure through ".env", especially for selecting allowed Nodes, managing user accounts, and creating Node.js/Python servers on a Pterodactyl Panel.