B

You are an Expert Discord Bot Developer specializing in Discord.js v14 (latest) and Node.js v20+. I need a highly advanced, lag-free, and well-optimized Discord bot for my Pterodactyl-based server hosting company.

Please write the complete, ready-to-use code (split into modules/handlers for commands and events) based on the following strict requirements. Leave clear placeholders like [YOUR_BOT_TOKEN_HERE] for me to fill in my credentials.

CORE FEATURE 1: Auto-Updating Status Monitor

  1. Command: /setup-status (Admin only slash command).
  2. Behavior: When this command is run in a channel, the bot will send a visually appealing Embedded Message. The bot must save this message ID and channel ID to a local JSON or SQLite database so it survives bot restarts.
  3. Auto-Refresh: The bot must edit and update this exact message every 15 seconds automatically using setInterval. Ensure rate limits are handled gracefully.
  4. Embed Content Requirements:

- Panel Status: Ping the main Pterodactyl panel URL. Show Online or Offline. - Server Statistics: Fetch data from the Pterodactyl Application API. Display: Total Servers, Online Servers, and Offline Servers. - Node Statistics: Fetch all nodes from the Pterodactyl API. - CRITICAL NAMING RULE: Do NOT use the actual names of the nodes from the API. You must rename them sequentially based on their count. E.g., if there are 4 nodes, display them as "Node 1", "Node 2", "Node 3", "Node 4". If a new node is added, it automatically becomes "Node 5". - Node Data: For each node, show its status ( Online / Offline) and its Uptime (e.g., "Online for 5d 12h" - calculate this from the API response or generic ping if not available).

CORE FEATURE 2: 100% Accurate GB to MB Digital Converter

  1. Command: /convert <gb> (Slash command where <gb> is an integer or decimal).
  2. Behavior: Must convert Gigabytes to Megabytes using exact digital storage mathematics (1 GB = 1024 MB).
  3. Output: A clean embed showing the exact result. (e.g., Input: 2 GB -> Output: 2048 MB). Do not use 1000 MB, it must be strictly 1024 MB for server RAM allocation accuracy.

BONUS FEATURES (Please include these slash commands):

  1. /ping: Shows the bot's websocket latency and API response time.
  2. /clear <amount>: Admin command to bulk delete up to 100 messages in a channel (useful to keep the status channel clean).
  3. /nodeinfo <node_number>: Displays detailed stats (RAM/Disk usage) of a specific node (Node 1, Node 2, etc.) using the Pterodactyl API. This command only use admin no any normal by any default player only use admin this particular command

TECHNICAL REQUIREMENTS:

  • Use axios or node-fetch for API requests.
  • Use discord.js v14 slash command builder.
  • Provide the exact package.json dependencies I need to install.
  • Comment the code thoroughly so I know exactly where to paste my Panel URL and Application API Key.

Panel URL https://panel.titannodes.fun Panel API key ptla_NDEDZM6Px5oAZlUKL8PWOBeoKFqkBkEe7KZyMEiraRb Discord bot token <redacted>

Kodari AI
KodariMay 8 at 1:26 pm 12,838 (v2)

Iโ€™ll create a professional Discord bot for Pterodactyl panel monitoring with all the advanced features you requested.

PterodactylMonitor
Professional Discord bot for Pterodactyl hosting panel integration. Features real-time auto-updating status embeds (15s refresh) showing panel health, server statistics, and sequential node monitoring. Includes accurate GB to MB converter (1024 base), admin tools for message management, and detailed node analytics via API. Persistent storage ensures reliability across restarts.

๐ŸŽ‰ Project Created Successfully!

Installation Steps:

Shell
# 1. Install dependencies
npm install

# 2. Deploy slash commands to Discord
npm run deploy

# 3. Start the bot
npm start

Your credentials are already configured:

Key Features Implemented:

  1. Auto-Updating Status Monitor - Updates every 15 seconds with panel health, server counts, and sequential node status (Node 1, Node 2, etc.)

  2. GB to MB Converter - Accurate 1024-base conversion for server RAM allocation

  3. Admin Commands - /clear for message management, /nodeinfo for detailed node statistics

  4. Permission System - Admin-only commands with role-based access control

  5. Persistent Storage - Status monitor survives bot restarts using JSON storage

  6. Rate Limit Handling - Proper error handling and API throttling

The bot is production-ready and optimized for performance! ๐Ÿš€

B

Please update the embed generation code for my Discord status bot. I want to change the layout of the embed to strictly match the exact structure below.

STRICT RULES:

  1. Do NOT add any extra fields like "System Load", "Storage Health", "Active Players", etc. Remove them completely.
  2. The "Total Servers", "Online Servers", and "Offline Servers" data must be moved to the very bottom of the embed in a single line or section.
  3. Node names must remain sequential (Node 1, Node 2, etc.).
  4. Keep the exact formatting, emojis, and structure as shown below.

REQUIRED EMBED LAYOUT:

๐ŸŒ Network Overview Panel Status: [๐ŸŸข Online / ๐Ÿ”ด Offline] Last Updated: [Dynamic Timestamp]

๐Ÿ“Š Node Infrastructure Node 1 Status: [๐ŸŸข Online / ๐Ÿ”ด Offline] | Uptime: [0d 0h 0m] Node 2 Status: [๐ŸŸข Online / ๐Ÿ”ด Offline] | Uptime: [0d 0h 0m] [... repeat for all existing nodes]

๐Ÿ“ˆ Server Statistics Total Servers: [Total Count] | Online: [Online Count] | Offline: [Offline Count]

Kodari AI
KodariMay 8 at 1:39 pm 11,471 (v2)

Iโ€™ll update the embed generation code to match your exact layout requirements.

โœ… Embed layout updated successfully!

The status monitor now displays exactly as you specified:

Changes Made:

  1. โœ… Network Overview section added to description with Panel Status and dynamic Last Updated timestamp

  2. โœ… Node Infrastructure field lists all nodes sequentially (Node 1, Node 2, etc.) with status and uptime in the exact format

  3. โœ… Server Statistics moved to the bottom as a single-line field

  4. โœ… Removed all extra fields (System Load, Storage Health, etc.)

  5. โœ… Offline nodes now show โ€œ0d 0h 0mโ€ uptime

  6. โœ… Online nodes show accurate uptime in โ€œXd Xh Xmโ€ format

  7. โœ… Used exact emojis: ๐ŸŒ ๐Ÿ“Š ๐Ÿ“ˆ ๐ŸŸข ๐Ÿ”ด

Example Output:

Plain Text
๐ŸŒ Network Overview
Panel Status: ๐ŸŸข Online
Last Updated: 2 seconds ago

๐Ÿ“Š Node Infrastructure
Node 1
Status: ๐ŸŸข Online | Uptime: 5d 12h 30m

Node 2
Status: ๐Ÿ”ด Offline | Uptime: 0d 0h 0m

๐Ÿ“ˆ Server Statistics
Total Servers: 10 | Online: 8 | Offline: 2

Restart your bot to see the new layout! ๐Ÿš€

B

Please rewrite the Discord bot code to use "Prefix Commands" instead of (or in addition to) Slash Commands, as the slash commands are not appearing in the server.

STRICT REQUIREMENTS:

  1. PREFIX: Use "!" as the default prefix for all commands.
  2. COMMANDS TO CONVERT:

- !setup-status: Sends the auto-updating status embed (15s refresh). - !convert <gb>: 100% accurate GB to MB converter (1024 multiplier). - !ping: Shows bot latency. - !nodeinfo <number>: Shows details for specific nodes. - !clear <amount>: Deletes messages (Admin only).

  1. FIX SYNTAX ERRORS:

- Ensure the statusMonitor.js file has no syntax errors on Line 64. - The status line MUST be: const status = node.online ? '๐ŸŸข Online' : '๐Ÿ”ด Offline';

  1. EMBED LAYOUT (Strictly follow this):

- Header: ๐ŸŒ Network Overview (Panel Status & Last Updated) - Body: ๐Ÿ“Š Node Infrastructure (Sequential naming: Node 1, Node 2, etc. with Status & Uptime) - Footer: ๐Ÿ“ˆ Server Statistics (Total, Online, and Offline servers in one line) - REMOVE: "Storage Health", "System Load", or any other extra fields.

  1. BACKGROUND RUNNING:

- Ensure the bot is optimized for PM2 and handles API rate limits gracefully. - Use 'messageCreate' event for prefix command handling.

Kodari AI
KodariMay 8 at 5:36 pm 22,139 (v2)

Iโ€™ll convert the bot to use prefix commands and fix all syntax errors.

Now Iโ€™ll convert the bot to use prefix commands:


โœ… Bot Converted to Prefix Commands Successfully!

๐ŸŽ‰ What Was Fixed:

  1. โœ… Fixed Syntax Error - Line 64 in statusMonitor.js now reads: const status = node.online ? '๐ŸŸข Online' : '๐Ÿ”ด Offline';

  2. โœ… Prefix Commands Active - Prefix set to ! (configurable in config.json)

  3. โœ… All Commands Converted:

    • !setup-status - Auto-updating status monitor

    • !convert <gb> - GB to MB converter (1024 base)

    • !ping - Bot latency check

    • !nodeinfo <number> - Detailed node stats (Admin only)

    • !clear <amount> - Bulk message deletion (Admin only)

    • !help - Command list

  4. โœ… Exact Embed Layout as specified (Network Overview โ†’ Node Infrastructure โ†’ Server Statistics)

  5. โœ… PM2 Optimized - Handles errors gracefully for background running

๐Ÿš€ Quick Start:

Shell
npm install
npm start

๐Ÿ”‘ Important: Enable Message Content Intent

Go to Discord Developer Portal โ†’ Your Bot โ†’ Bot Section โ†’ Enable MESSAGE CONTENT INTENT (required for prefix commands to work!)

Your bot is now ready to use with prefix commands! ๐ŸŽŠ

B

Please update the Discord bot code to fix the Uptime calculation and Server Statistics tracking.

CRITICAL FIXES REQUIRED:

  1. ACTUAL UPTIME (NOT CREATION DATE):

- Currently, the bot calculates uptime based on 'created_at' timestamp. This is wrong. - UPDATE: The bot must fetch the actual uptime from the Pterodactyl Wings (Daemon). If the node is online, show the duration since it last started/connected. If the Wings API doesn't provide a direct 'boot_time', use a ping-based heart-beat tracker to show how long the node has been continuously reachable without a restart.

  1. REAL-TIME SERVER TRACKING:

- The "Online/Offline" server count is currently stuck or inaccurate. - FIX: Ensure that for EVERY status refresh (15 seconds), the bot makes a fresh call to the Pterodactyl Application API for server resources. - It must check the 'status' or 'current_state' attribute of each server. If a server is 'running', count it as Online. If it's anything else, count it as Offline.

  1. EMBED LAYOUT (Strict Maintenance):

- Keep the sequential naming (Node 1, Node 2, etc.). - The footer must show: Total Servers: [X] | Online: [Y] | Offline: [Z] in one line. - Frequency: Maintain the 15-second auto-refresh interval.

  1. PREFIX COMMANDS:

- Ensure these updates apply to the Prefix system (!) as previously requested.

Please provide the corrected logic for 'utils/pterodactyl.js' and 'utils/statusMonitor.js'.

Kodari AI
KodariMay 9 at 5:06 am 18,879 (v2)

Iโ€™ll fix the uptime calculation and real-time server statistics tracking.

Now let me update the README to document the CLIENT_API_KEY requirement:


โœ… CRITICAL FIXES APPLIED SUCCESSFULLY!

๐Ÿ”ง What Was Fixed:

1๏ธโƒฃ ACCURATE UPTIME TRACKING (NOT CREATION DATE)

  • โœ… Implemented persistent uptime tracking system in data/status.json

  • โœ… Records the exact timestamp when each node comes online

  • โœ… Calculates uptime based on actual online duration, not creation date

  • โœ… Automatically resets uptime when a node goes offline and comes back online

  • โœ… Shows โ€œ0d 0h 0mโ€ for offline nodes

How it works:

JavaScript
// When a node comes online โ†’ timestamp is recorded
// Uptime = Current Time - Recorded Online Timestamp
// When node goes offline โ†’ timestamp is cleared

2๏ธโƒฃ REAL-TIME SERVER STATISTICS

  • โœ… Fresh API call every 15 seconds to fetch server states

  • โœ… Uses Pterodactyl Client API to get accurate current_state of each server

  • โœ… Checks if server is running โ†’ counts as Online

  • โœ… Any other state (offline, stopping, starting, suspended) โ†’ counts as Offline

  • โœ… Graceful fallback: If Client API key is missing, shows total servers only

To enable accurate online/offline tracking: Add this to your .env file:

Env
CLIENT_API_KEY=ptlc_YourClientAPIKeyHere

Get your Client API Key from: Pterodactyl Panel โ†’ Account Settings โ†’ API Credentials โ†’ Create New

3๏ธโƒฃ EMBED LAYOUT (STRICTLY MAINTAINED)

โœ… Sequential naming: Node 1, Node 2, Node 3, etc. โœ… Footer format: Total Servers: X | Online: Y | Offline: Z โœ… 15-second auto-refresh interval preserved โœ… Prefix commands !) fully functional


๐Ÿ“Š Example Output:

Plain Text
๐ŸŒ Network Overview
Panel Status: ๐ŸŸข Online
Last Updated: 2 seconds ago

๐Ÿ“Š Node Infrastructure
Node 1
Status: ๐ŸŸข Online | Uptime: 5d 12h 30m

Node 2
Status: ๐ŸŸข Online | Uptime: 2d 3h 45m

Node 3
Status: ๐Ÿ”ด Offline | Uptime: 0d 0h 0m

๐Ÿ“ˆ Server Statistics
Total Servers: 25 | Online: 18 | Offline: 7

๐Ÿš€ How to Apply Changes:

Shell
# Restart the bot
npm start

# Or if using PM2:
pm2 restart pterodactyl-bot

โšก Key Technical Changes:

File: utils/pterodactyl.js

  • Added calculateRealUptime() - Uses tracked timestamps instead of created_at

  • Added getServerStatsRealTime() - Fetches live server states via Client API

  • Added getServerResources() - Helper to query individual server status

  • Automatic fallback if Client API key is missing

File: utils/statusMonitor.js

  • Added loadUptimeTracking() and saveUptimeTracking() functions

  • Tracks node state changes (offline โ†’ online transitions)

  • Records timestamps in data/status.json persistently

  • Integrates real-time server stats into embed

File: data/status.json

  • New structure stores node uptime timestamps:

JSON
{
  "channelId": "1234567890",
  "messageId": "0987654321",
  "nodeUptime": {
    "1": 1735689123456,
    "2": 1735689234567
  }
}

๐Ÿ”‘ IMPORTANT: Add Client API Key

For 100% accurate online/offline server counts, add your Client API key to .env:

Env
CLIENT_API_KEY=ptlc_YourClientAPIKeyHere

How to get it:

  1. Go to your Pterodactyl Panel

  2. Navigate to Account Settings โ†’ API Credentials

  3. Click Create New โ†’ Copy the key

  4. Paste it into .env as shown above

  5. Restart the bot

Without Client API Key:

  • Server statistics will show: Total Servers: 25 (no online/offline breakdown)

With Client API Key:

  • Server statistics will show: Total Servers: 25 | Online: 18 | Offline: 7 โœ…


Your bot now tracks actual node uptime and provides real-time server statistics! ๐ŸŽ‰

B

Please update the Discord bot's status monitor logic to replace the "Duration-based Uptime" with a "Reliability Percentage (Uptime %)".

NEW LOGIC REQUIREMENTS:

  1. TRACKING UPTIME PERCENTAGE:

- Instead of showing "0d 0h 1m", calculate the uptime percentage for each Node. - The bot must track how many successful pings (Online) vs failed pings (Offline) occur for each Node over time. - Formula: (Total Successful Checks / Total Total Checks) * 100. - Example Display: "Node 1 Status: ๐ŸŸข Online | Uptime: 99.98%"

  1. INDIVIDUAL TRACKING:

- Each node (Node 1, Node 2, etc.) must have its own separate percentage calculation. - Store this data in the local 'data/status.json' or a new 'data/uptime_stats.json' so the percentage is not lost when the bot restarts.

  1. REAL-TIME SERVER STATS FIX:

- Ensure the "Server Statistics" footer (Total/Online/Offline) continues to fetch live data from the Pterodactyl API every 15 seconds as shown in the latest screenshot.

  1. EMBED CLEANUP:

- Remove the duration time (days/hours/minutes) completely. - Keep the sequential naming: Node 1, Node 2, Node 3, Node 4.

Please provide the updated 'utils/statusMonitor.js' and 'utils/pterodactyl.js' to implement this percentage-based tracking system.

Kodari AI
KodariMay 9 at 5:21 am 15,536 (v2)

Iโ€™ll update the bot to use uptime percentage tracking instead of duration-based uptime.

Now let me update the README to document the new uptime percentage system:


โœ… Uptime Percentage Tracking Implemented Successfully!

๐ŸŽฏ What Changed:

  1. โœ… Percentage-Based Uptime Tracking

    • Replaced duration format (5d 12h 30m) with reliability percentage (99.98%)

    • Formula: (Successful Checks / Total Checks) ร— 100

    • Each check (every 15 seconds) increments the total count

    • Online checks increment the successful count

  2. โœ… Persistent Storage

    • Created data/uptime_stats.json for separate uptime tracking

    • Stores individual node statistics: { "nodeId": { "total": 1000, "successful": 998 } }

    • Data survives bot restarts (percentages continue tracking)

  3. โœ… Individual Node Tracking

    • Node 1, Node 2, Node 3, Node 4 each have separate percentage calculations

    • Offline nodes show their historical percentage (not reset to 0%)

    • New nodes start at 0.00% and build reliability over time

  4. โœ… Embed Display Updated

    • Format: Status: ๐ŸŸข Online | Uptime: 99.98%

    • Offline: Status: ๐Ÿ”ด Offline | Uptime: 95.42% (shows historical reliability)

    • Server Statistics continue to fetch live data every 15 seconds

  5. โœ… Files Modified:

    • utils/pterodactyl.js - Replaced calculateUptime() with calculateUptimePercentage()

    • utils/statusMonitor.js - Updated display logic to use percentage

    • Created data/uptime_stats.json - New persistent storage file

    • Updated README.md - Documented new tracking system

๐Ÿ“Š Example Output:

Plain Text
๐ŸŒ Network Overview
Panel Status: ๐ŸŸข Online
Last Updated: 2 seconds ago

๐Ÿ“Š Node Infrastructure
Node 1
Status: ๐ŸŸข Online | Uptime: 99.98%

Node 2
Status: ๐ŸŸข Online | Uptime: 100.00%

Node 3
Status: ๐Ÿ”ด Offline | Uptime: 95.42%

Node 4
Status: ๐ŸŸข Online | Uptime: 98.75%

๐Ÿ“ˆ Server Statistics
Total Servers: 10 | Online: 8 | Offline: 2

๐Ÿš€ How It Works:

  • Every 15 seconds, the bot checks each nodeโ€™s status

  • Total checks increments by 1 for each node

  • Successful checks increments by 1 if the node is online

  • Percentage displayed = (successful รท total) ร— 100

  • Data persists in data/uptime_stats.json across restarts

Restart your bot to see the new percentage-based uptime tracking! ๐ŸŽŠ

Kodari can make mistakes. Review important code before using.
Files
commands
data
events
utils
.gitignore
config.json
index.js
package.json
README.md
Code
18 1,167
index.js
const { Client, GatewayIntentBits, Collection, ActivityType } = require('discord.js');
const { startStatusMonitor } = require('./utils/statusMonitor');
const fs = require('fs');
const path = require('path');
require('dotenv').config();

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
  const filePath = path.join(commandsPath, file);
  const command = require(filePath);
  if ('name' in command && 'execute' in command) {
    client.commands.set(command.name, command);
    console.log(`โœ… Loaded command: ${command.name}`);
  } else {
    console.log(`โš ๏ธ Command at ${filePath} is missing required "name" or "execute" property.`);
  }
}

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
  const filePath = path.join(eventsPath, file);
  const event = require(filePath);
  if (event.once) {
    client.once(event.name, (...args) => event.execute(...args));
  } else {
    client.on(event.name, (...args) => event.execute(...args));
  }
  console.log(`โœ… Loaded event: ${event.name}`);
}

client.once('ready', () => {
  console.log(`\n๐Ÿš€ Bot is online as ${client.user.tag}`);
  console.log(`๐Ÿ“Š Serving ${client.guilds.cache.size} server(s)`);
  console.log(`๐Ÿ”ง Prefix: ${require('./config.json').prefix}`);
  
  client.user.setPresence({
    activities: [{ name: 'Pterodactyl Panel | !help', type: ActivityType.Watching }],
    status: 'online'
  });

  startStatusMonitor(client);
  console.log('๐Ÿ“ก Status monitor started\n');
});

process.on('unhandledRejection', error => {
  console.error('Unhandled promise rejection:', error);
});

process.on('uncaughtException', error => {
  console.error('Uncaught exception:', error);
});

client.login(process.env.DISCORD_TOKEN);