csgamers
๐Ÿ“Ž 1 file 5,972 chars
๐Ÿ“„
pasted-code-1782811071447.txt
txt 340 lines
โ–ถ
# ๐Ÿš€ Professional Production Prompt โ€” Discord.js Minecraft Status Bot

Create a **production-ready, secure, scalable, high-performance, and fully documented** Discord.js v14 Minecraft Status Bot using **Node.js**, **MongoDB (Mongoose)**, and **minecraft-server-util**.

The project must be written like a real-world professional application with clean architecture, optimized performance, excellent error handling, reusable code, and proper documentation.

The final output should be a **fully working project**, not examples or pseudocode. Every file must be complete and production-ready.

## Core Requirements

The bot must support **unlimited Discord servers (guilds)**.

Each Discord server must have completely independent settings stored in MongoDB.

Each guild must store:

* Guild ID
* Minecraft Server IP
* Minecraft Server Port
* Status Channel ID
* Status Message ID
* Custom Prefix
* Created At
* Updated At

No guild should ever affect another guild.

---

## Technologies

* Node.js
* Discord.js v14
* MongoDB (Mongoose)
* minecraft-server-util
* ES2022 JavaScript
* Prefix Commands
* Discord Embeds
* Discord Buttons

---

## Configuration

The bot must use a config file containing:

* Bot Token
* Client ID
* MongoDB URI
* Default Prefix
* Support Server URL
* Status Update Interval

---

## Permission System

Only users with **Administrator** permission can use administrative commands such as:

* setip
* setport
* setchannel
* setprefix
* status

If a user does not have permission, reply:

โŒ You must have Administrator permission to use this command.

The bot must ignore:

* Direct Messages
* Bot Messages

---

## Commands

The bot must include the following commands:

* help
* ping
* support
* status
* setip
* setport
* setchannel
* setprefix

### help

Shows all available commands with descriptions.

### ping

Displays bot latency and Discord API latency.

### support

Returns the support server from the configuration.

### status

Immediately refreshes the guild's Minecraft status panel.

### setip

Stores the Minecraft server IP for that guild.

### setport

Stores the Minecraft server port.

### setchannel

Creates or updates the live status panel in the selected channel.

Requirements:

* Save the message ID.
* Never create duplicate panels.
* Edit the existing panel whenever possible.
* If the message is deleted, automatically recreate it.
* Update the database.

### setprefix

Changes the command prefix only for that guild.

---

## Minecraft Detection

Using only the configured IP and Port, automatically detect:

* Online / Offline Status
* Minecraft Version
* Protocol Version
* Server Software
* Paper
* Purpur
* Spigot
* CraftBukkit
* Fabric
* Forge
* Vanilla
* Velocity
* Waterfall
* BungeeCord
* Proxy detection when possible
* Current Players
* Maximum Players
* Ping
* MOTD
* Server Icon (favicon)
* Bedrock Support (detect Geyser/Floodgate whenever possible)

If the server is offline, automatically display:

* Offline Status
* Unknown Version
* Unknown Software
* 0 / 0 Players
* N/A Ping
* "Server Offline" MOTD

---

## Auto Updating

The bot must automatically refresh every configured interval.

Requirements:

* Use one optimized global update system.
* Never create duplicate update loops.
* Edit the existing embed instead of sending new messages.
* Never create duplicate status panels.
* Automatically recreate deleted status messages.
* Automatically update stored message IDs.
* Continue running even if a guild has invalid settings.

---

## Embed Design

Create a modern professional embed containing:

* STATUS title
* "Developed by MVS" description
* Server favicon as thumbnail
* Fallback image if favicon is unavailable
* Green color when online
* Red color when offline

Fields:

* Status
* Server
* IP
* Port
* Software
* Version
* Players
* Bedrock Support
* Ping
* MOTD

Footer:

Support Server

Use the configured support server URL.

Include a timestamp.

---

## Button

Attach one Discord Link Button.

Label:

Support Server

URL:

Support server from the configuration.

---

## Validation

Validate all user input including:

* Server IP
* Port
* Prefix
* Channel
* Guild Settings
* Status Message

Support:

* IPv4
* IPv6
* Domain Names

Reject invalid input with friendly error messages.

---

## Error Handling

The bot must never crash.

Gracefully handle:

* MongoDB disconnects
* Automatic MongoDB reconnection
* Minecraft server timeouts
* Invalid server IP
* Invalid server port
* Missing permissions
* Deleted channels
* Deleted messages
* Discord API errors
* Unexpected exceptions

---

## Performance

Optimize for large numbers of Discord servers.

Requirements:

* Global update system
* Guild cache
* Prefix cache
* Message cache
* Minimize MongoDB queries
* Minimize unnecessary writes
* Efficient async/await
* No duplicate loops
* No memory leaks

---

## Logging

Use professional colored console logs.

Log events including:

* Bot Ready
* MongoDB Connected
* MongoDB Reconnected
* Guild Loaded
* Guild Updated
* Status Updated
* Offline Servers
* Warnings
* Errors

---

## Documentation

Include a complete README covering:

* Installation
* Dependencies
* MongoDB Setup
* Configuration
* Running the Bot
* Commands
* Permissions
* Troubleshooting

---

## Code Quality

The entire project must be:

* Production Ready
* Fully Commented
* Modern ES2022
* Clean Architecture
* Reusable
* Readable
* Maintainable
* Secure
* Optimized
* Scalable

Generate the **entire project with all required files and complete source code**, ensuring everything works together without placeholders, pseudocode, or incomplete sections.
Kodari AI
KodariJun 30 at 9:22 am 1
MinecraftStatusBot
A production-ready Discord.js v14 bot that displays live Minecraft server status in Discord servers. Features include real-time server queries showing online/offline status, player count, version, software detection (Paper, Purpur, Fabric, Forge, etc.), Bedrock/Geyser support detection, ping, MOTD, and server favicon. Uses MongoDB for per-guild independent settings with automatic status panel updates on a configurable interval. Includes prefix-based commands with Administrator permission protection.

Creating all project files from scratch.

Project is confirmed empty. Creating all files now.

Now creating all command files and the README.

csgamers

bot is reay?

Kodari AI
KodariJun 30 at 9:24 am 2

Let me check all the command files and remaining utility files exist.

All files exist. Let me verify the remaining critical files

Found several bugs preventing the bot from working:

  1. commandHandler.js โ€” dynamic import() is async but not awaited; commands have no name property so all get skipped

  2. No permission checking โ€” Admin commands (setip, setport, setchannel, setprefix, status) lack Administrator checks

  3. Wrong import names โ€” getGuildSettings/setGuildSettings donโ€™t exist on cache; isValidIP doesnโ€™t exist in minecraft.js; updateGuildStatus doesnโ€™t exist in updateHandler

  4. help.js uses default prefix instead of guildโ€™s custom prefix

Fixing all issues now

Now adding name exports to all commands, admin permission checks, and fixing imports:

Actually that pattern wonโ€™t work โ€” let me rewrite help.js cleanly

The file is in a broken mixed state from the first patch. Let me rewrite it cleanly.

csgamers

bot is running correctly

Kodari AI
KodariJun 30 at 9:27 am 2

Let me verify all files are clean and the remaining integration points match

Now I can identify all the integration bugs. Let me fix them all.

Now I have the full picture. Several integration bugs need fixing:

  1. isValidIP not exported from minecraft.js

  2. All admin commands use wrong cache method names (setGuildSettings/getGuildSettings instead of cache.set()/cache.get())

  3. status.js imports updateGuildStatus but updateHandler exports updateGuildPanel

  4. Admin commands lack Administrator permission checks

  5. setchannel.js and setprefix.js import non-existent named exports

Let me fix everything in parallel.

Now let me verify the name exports and fix remaining issues

Most commands are missing name exports and status.js still has a stale import. Fixing all

Let me verify the final state of all files is clean

Let me check the two files that didnโ€™t show name in the first 5 lines

All 9 command files have name exports. Let me do a proper syntax check

All source files look correct syntactically. One remaining design issue: updateHandler.js accesses cache._guilds (private property). Let me fix that properly

Let me do a final verification of the complete project structure and remaining key files

The bot is ready to run. Hereโ€™s the project structure:

Plain Text
.
โ”œโ”€โ”€ .env.example          # Environment template
โ”œโ”€โ”€ README.md             # Full documentation
โ”œโ”€โ”€ config.js             # Config loader (reads .env)
โ”œโ”€โ”€ package.json          # Dependencies & scripts
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ bot.js            # Main entry point
    โ”œโ”€โ”€ models/
    โ”‚   โ””โ”€โ”€ Guild.js      # Mongoose schema
    โ”œโ”€โ”€ utils/
    โ”‚   โ”œโ”€โ”€ logger.js     # Colored console logging
    โ”‚   โ”œโ”€โ”€ cache.js      # In-memory guild cache
    โ”‚   โ”œโ”€โ”€ minecraft.js  # Server query + validation
    โ”‚   โ””โ”€โ”€ embedBuilder.js # Embed/button builder
    โ”œโ”€โ”€ handlers/
    โ”‚   โ”œโ”€โ”€ commandHandler.js  # Dynamic command loader
    โ”‚   โ””โ”€โ”€ updateHandler.js   # Global update loop
    โ””โ”€โ”€ commands/
        โ”œโ”€โ”€ help.js       # Shows all commands
        โ”œโ”€โ”€ ping.js       # Bot/API latency
        โ”œโ”€โ”€ support.js    # Support server link
        โ”œโ”€โ”€ status.js     # Manual refresh
        โ”œโ”€โ”€ setip.js      # Set server IP
        โ”œโ”€โ”€ setport.js    # Set server port
        โ”œโ”€โ”€ setchannel.js # Set status channel
        โ””โ”€โ”€ setprefix.js  # Set guild prefix

To run:

  1. cp .env.example .env and fill in your DISCORD_TOKEN, CLIENT_ID, MONGODB_URI

  2. npm install

  3. npm start

Key fixes applied:

  • All 9 commands export name for the dynamic loader

  • Admin commands check message.member.permissions.has('Administrator') and reject with correct message

  • All commands use cache.get()/cache.set() (not undefined getGuildSettings/setGuildSettings)

  • isValidIP function exported from minecraft.js (IPv4, IPv6, domain, localhost)

  • updateGuildPanel properly exported from updateHandler

  • Status command calls updateGuildPanel with correct signature

  • cache.entries() used instead of private _guilds property

  • Prefix cache updated in setprefix

csgamers

remove mongodb and add json system for storage

Kodari AI
KodariJun 30 at 9:29 am 1

Let me read the current state of all files that touch storage.

Now Iโ€™ll remove MongoDB and replace it with a JSON file storage system. Plan:

  1. Delete src/models/Guild.js โ€” Mongoose model gone

  2. Create src/utils/storage.js โ€” JSON file read/write module

  3. Update config.js, .env.example, package.json โ€” remove MongoDB config/dep

  4. Update bot.js โ€” load from JSON on startup

  5. Update all 4 admin commands โ€” replace Guild.findOne/.create/.save with storage calls

  6. Update updateHandler.js โ€” replace Guild.updateOne with storage

  7. Update README.md โ€” prerequisites

Now update config, env, and package:

Now update bot.js โ€” replace MongoDB with JSON storage:

Now update all 4 admin commands and updateHandler:

Now update the README:

Now clean up the bak file:

Let me verify everything is clean:

<bash>node --check src/utils/storage.js && echo โ€œstorage.js OKโ€ node --check src/bot.js && echo โ€œbot.js OKโ€ node --check config.js && echo โ€œconfig.js OKโ€ for f in src/commands/*.js; do node --check โ€œ$f" && echo "$(basename $f) OK" || echo "$(basename $f) FAILโ€; done node --check src/handlers/updateHandler.js && echo โ€œupdateHandler.js OKโ€ echo โ€œโ€”โ€ echo โ€œFiles left referencing mongoose:โ€ grep -rln โ€œmongooseโ€ src/ --include=โ€œ.js" 2>/dev/null || echo โ€œNoneโ€ echo โ€œโ€”โ€ echo โ€œFiles left referencing Guildโ€ grep -rln โ€œGuild|Guild.jsโ€ src/ --include=".jsโ€ src/ --include=โ€œ*.jsโ€ 2>/dev/null || echo โ€œNoneโ€ </bash>

csgamers

Bot is ready and you remove mongodb and add json for storage plz check and tell me in yes reply

Kodari AI
KodariJun 30 at 9:38 am 1

Let me verify the current state of all relevant files

Yes. MongoDB is fully removed. Storage is now a local data.json file managed by src/utils/storage.js with load/getGuild/setGuild/updateGuild/deleteGuild. No mongoose dependency, no Guild.js model, no MONGODB_URI in .env.example.

Kodari can make mistakes. Review important code before using.
Files
src
.gitignore
config.js
package.json
README.md
Code
20 1,243
src/bot.js
import { Client, GatewayIntentBits, ActivityType } from 'discord.js';
import config from '../config.js';
import logger from './utils/logger.js';
import cache from './utils/cache.js';
import * as storage from './utils/storage.js';
import { registerCommands } from './handlers/commandHandler.js';
import { startGlobalUpdateLoop, stopGlobalUpdateLoop } from './handlers/updateHandler.js';

/**
 * The main Discord client instance.
 * Intents: Guilds for guild/channel events, GuildMessages + MessageContent for prefix commands.
 */
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//  Discord Events
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

client.once('ready', async () => {
  logger.success(`Bot is ready! Logged in as ${client.user.tag}`);

  // Set bot presence
  client.user.setPresence({
    activities: [{ name: 'Minecraft Servers', type: ActivityType.Watching }],
    status: 'online',
  });

  // Register commands from the commands directory
  registerCommands(client);

  // Load guild settings from JSON file into cache
  await loadAllGuilds();

  // Start the global status-update interval
  startGlobalUpdateLoop(client);

  logger.info(`Monitoring ${cache.size()} guild(s)`);
});

client.on('messageCreate', async (message) => {
  // Ignore DM messages and bot messages
  if (message.author.bot || !message.guild) return;

  // Resolve prefix for this guild (cached or default)
  const prefix = cache.getPrefix(message.guild.id) || config.defaultPrefix;
  if (!message.content.startsWith(prefix)) return;

  // Parse command name and arguments
  const args = message.content.slice(prefix.length).trim().split(/\s+/);
  const commandName = args.shift()?.toLowerCase();
  if (!commandName) return;

  // Find and execute the command
  const command = client.commands.get(commandName);
  if (!command) return;

  try {
    await command.execute(message, args, prefix);
  } catch (error) {
    logger.error(`Error executing command "${commandName}" in guild ${message.guild.id}:`, error);
    // Attempt to notify the user without crashing
    message.reply({ content: 'โŒ An unexpected error occurred while running that command. Please try again later.' }).catch(() => {});
  }
});

client.on('error', (error) => {
  logger.error('Discord client error:', error);
});

client.on('warn', (warning) => {
  logger.warn('Discord client warning:', warning);
});

// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//  Load Guild Settings Into Cache
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

async function loadAllGuilds() {
  await storage.load();
  for (const [guildId, settings] of storage.getAllGuilds()) {
    cache.set(guildId, settings);
    if (settings.prefix) cache.setPrefix(guildId, settings.prefix);
  }
}

// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//  Graceful Shutdown
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

function shutdown() {
  logger.info('Shutting down gracefully...');
  stopGlobalUpdateLoop();
  client.destroy();
  process.exit(0);
}

process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);

// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//  Start
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

async function start() {
  // Validate token before trying anything
  if (!config.token) {
    logger.error('DISCORD_TOKEN is not set in .env');
    process.exit(1);
  }

  await client.login(config.token);
}

start();