nawajahmad3535-afk

---

Discord Bot Prompt: GodWhitelist Bot

Create a professional Discord bot named GodWhitelist.

Developer Credit: SkyKing01

---

Main Purpose

GodWhitelist is a Discord-based whitelist management system for Minecraft servers.

Players can whitelist themselves by sending their Minecraft username in a specific Discord channel.

The bot validates usernames and manages whitelist data automatically.

---

Core Features

  1. Auto Whitelist System

The bot must monitor a configured Discord channel.

When a user sends a message like:

Steve

The bot must:

Validate Minecraft username format (A-Z, a-z, 0-9, underscore)

Ignore bot messages

Ignore invalid usernames

Check if the player is already whitelisted

Add the player to the whitelist database

Confirm successful whitelisting

Log actions in console

Response example:

Steve has been successfully whitelisted.

---

  1. Duplicate Protection

Prevent duplicate whitelist entries

If already whitelisted, respond:

You are already whitelisted.

---

  1. Auto Unwhitelist System (Inactivity)

Track each player's last activity.

If a player is inactive for a configurable number of days:

Default:

inactive-days: 10

Then:

Remove player from whitelist

Save removal record

Send notification

Log action in console

---

  1. Data Storage

Use YAML or JSON storage.

Store:

UUID

Username

Whitelist date

Last join date

Files:

players.yml config.yml

---

  1. Commands

/whitelist <player> Manually whitelist a player Permission: admin

/unwhitelist <player> Manually remove a player from whitelist Permission: admin

/gw reload Reload configuration Permission: admin

/gw status Show bot status

---

  1. Permissions

admin role required for management commands

normal users can only submit usernames in the whitelist channel

---

  1. Configuration (config.yml)

whitelist-enabled: true

inactive-days: 10

discord: bot-token: "" whitelist-channel-id: ""

messages: already-whitelisted: "You are already whitelisted." success: "You have been whitelisted." invalid-name: "Invalid Minecraft username." not-whitelisted: "You are not whitelisted."

---

  1. Logging System

Log all actions to console:

Player whitelisted

Duplicate attempts

Player removal due to inactivity

Errors and failures

---

  1. Webhook Notifications

Whitelist notification:

Player Whitelisted Player: Steve Date: {date}

Auto removal notification:

Player Unwhitelisted Player: Steve Reason: Inactive for 10 days

Manual whitelist notification:

Admin Whitelisted Player Player: Steve Admin: {admin}

---

  1. Technical Requirements

Discord.js v14 or JDA

Node.js 18+ or Java 21

Fully asynchronous message handling

Automatic reconnection system

Optimized for large servers

No memory leaks

Clean modular code structure

---

Startup Messages

[GodWhitelist] Loading configuration... [GodWhitelist] Connecting to Discord... [GodWhitelist] Discord connection successful. [GodWhitelist] Loading data... [GodWhitelist] Inactivity checker started. [GodWhitelist] Bot enabled.

---

Shutdown Messages

[GodWhitelist] Saving data... [GodWhitelist] Disconnecting from Discord... [GodWhitelist] Bot disabled.

Kodari AI
KodariJun 7 at 7:32 am 1

I’ll create the GodWhitelist Discord bot.

GodWhitelist
A Discord-based whitelist management system for Minecraft servers. Players auto-whitelist by sending their username in a configured channel. Features include username validation, duplicate protection, inactivity-based auto-removal, admin commands (/whitelist, /unwhitelist, /gw reload, /gw status), YAML data storage, webhook notifications, and comprehensive logging. Built with discord.js v14 and Node.js 18+.

Project structure:

Plain Text
GodWhitelist/
├── index.js              # Main entry — client setup, event wiring, lifecycle
├── package.json          # Dependencies
├── .env                  # DISCORD_TOKEN
├── config.yml            # Bot configuration
├── players.yml           # Generated at runtime — whitelist data
└── src/
    ├── logger.js         # Timestamped console logging
    ├── configManager.js  # YAML config loader with hot-reload
    ├── database.js       # YAML player data store (CRUD)
    ├── uuidResolver.js   # Mojang API UUID resolution
    ├── whitelistManager.js  # Core whitelist logic + validation
    ├── commandHandler.js # Slash commands (/whitelist, /unwhitelist, /gw)
    ├── inactivityChecker.js # Periodic inactivity sweep
    └── webhookManager.js # Discord webhook notifications

How to run:

  1. npm install

  2. Set your bot token in .env (or in config.yml under discord.bot-token)

  3. Set the whitelist channel ID in config.yml

  4. Optionally set webhook URL in config.yml

  5. npm start

Kodari can make mistakes. Review important code before using.
Files
src
config.yml
index.js
package.json
Code
11 698
index.js
require('dotenv').config();
const { Client, GatewayIntentBits, Events } = require('discord.js');
const Logger = require('./src/logger');
const ConfigManager = require('./src/configManager');
const Database = require('./src/database');
const WhitelistManager = require('./src/whitelistManager');
const CommandHandler = require('./src/commands');
const InactivityChecker = require('./src/inactivityChecker');
const WebhookManager = require('./src/webhookManager');

class GodWhitelist {
  constructor() {
    this.client = null;
    this.config = new ConfigManager();
    this.database = new Database();
    this.webhookManager = null;
    this.whitelistManager = null;
    this.commandHandler = null;
    this.inactivityChecker = null;
  }

  async start() {
    Logger.info('Loading configuration...');
    if (!this.config.load()) {
      process.exit(1);
    }

    const token = this.config.get('discord.bot-token') || process.env.DISCORD_TOKEN;
    if (!token) {
      Logger.error('No Discord bot token found. Set DISCORD_TOKEN in .env or discord.bot-token in config.yml.');
      process.exit(1);
    }

    Logger.info('Loading data...');
    this.database.load();

    this.webhookManager = new WebhookManager(this.config);
    this.whitelistManager = new WhitelistManager(this.database, this.config);

    Logger.info('Connecting to Discord...');

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

    this.commandHandler = new CommandHandler(
      this.client, this.whitelistManager, this.config, this.webhookManager, this.database
    );

    this.registerEventHandlers();
    await this.client.login(token);
  }

  registerEventHandlers() {
    this.client.once(Events.ClientReady, async () => {
      Logger.success('Discord connection successful.');
      await this.commandHandler.registerCommands();

      this.inactivityChecker = new InactivityChecker(this.whitelistManager, this.webhookManager);
      this.inactivityChecker.start();

      Logger.success('Bot enabled.');
      Logger.info(`Logged in as ${this.client.user.tag}`);
    });

    this.client.on(Events.MessageCreate, (message) => this.handleMessage(message));

    this.client.on(Events.InteractionCreate, (interaction) => {
      this.commandHandler.handleInteraction(interaction);
    });

    this.client.on(Events.Error, (error) => {
      Logger.error(`Discord client error: ${error.message}`);
    });

    this.client.on(Events.Warn, (warning) => {
      Logger.warn(`Discord client warning: ${warning}`);
    });

    this.client.on(Events.ShardDisconnect, (event) => {
      Logger.warn(`Disconnected from Discord. Code: ${event.code}. Reconnecting...`);
    });

    process.on('SIGINT', () => this.shutdown());
    process.on('SIGTERM', () => this.shutdown());
  }

  async handleMessage(message) {
    if (message.author.bot) return;

    const channelId = this.config.getWhitelistChannelId();
    if (!channelId || message.channel.id !== channelId) return;

    if (!this.config.isEnabled()) return;

    const username = message.content.trim();

    if (!this.whitelistManager.validateUsername(username)) {
      await message.reply(this.config.getMessage('invalid-name'));
      Logger.warn(`Invalid username attempt by ${message.author.tag}: ${username}`);
      return;
    }

    if (this.database.isWhitelisted(username)) {
      await message.reply(this.config.getMessage('already-whitelisted'));
      Logger.warn(`Duplicate whitelist attempt by ${message.author.tag}: ${username}`);
      return;
    }

    const result = await this.whitelistManager.whitelistPlayer(username, message.author.tag);

    if (result.success) {
      await message.reply(`✅ ${result.message}`);
      if (this.webhookManager) {
        await this.webhookManager.sendWhitelistNotification(result.username);
      }
    } else {
      await message.reply(`❌ ${result.message}`);
    }
  }

  async shutdown() {
    Logger.info('Saving data...');
    this.database.save();

    if (this.inactivityChecker) {
      this.inactivityChecker.stop();
    }

    Logger.info('Disconnecting from Discord...');

    if (this.client) {
      this.client.destroy();
    }

    Logger.success('Bot disabled.');
    process.exit(0);
  }
}

const bot = new GodWhitelist();
bot.start().catch((error) => {
  Logger.error(`Fatal error: ${error.message}`);
  process.exit(1);
});