Skip to content

About

AI-powered Discord administration bot with natural language commands, safe previews, confirmation flows, channel cleanup, message moderation, and multi-provider AI support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AI Discord Server Manager Bot

An AI-powered Discord administration bot that converts natural language commands into safe, structured server-management actions. The project is designed for Discord communities where administrators need faster ways to inspect, organize, clean up, and moderate a server without manually navigating every channel, category, role, or message.

Instead of exposing only rigid commands, the bot uses an AI planner to understand Romanian admin requests, validate them against the current Discord server snapshot, preview the expected impact, and execute the approved plan through a controlled action registry.

Why this project matters

Discord administration can become repetitive and risky, especially when managing large servers with many channels, categories, roles, members, and messages. This bot focuses on three important goals:

  1. Productivity – administrators can describe what they want in natural language.
  2. Safety – destructive or mutating actions require validation, preview, and confirmation.
  3. Maintainability – actions are organized into clear modules for channels, cleanup, messages, and server inspection.

This makes the project more than a simple command bot: it is a small AI-assisted automation system with permission checks, structured planning, execution safeguards, retry logic, and modular Discord operations.

Main features

Natural language AI planning

The bot receives an admin request, builds a snapshot of the Discord server, and asks an AI provider to return a strict JSON plan. The plan is validated before anything is executed.

Examples of supported request types:

  • “List all channels without a category”
  • “Create a new text channel in this category”
  • “Archive inactive channels”
  • “Delete empty categories”
  • “Purge messages containing invite links”
  • “Show server roles and moderators”

Safe plan validation

Before execution, the planner checks:

  • whether the AI returned a valid structured plan
  • whether every requested tool exists
  • whether IDs match known channels, categories, and roles
  • whether message/member IDs look valid
  • whether the plan exceeds configured safety limits
  • whether destructive actions require confirmation

Preview before dangerous actions

For mutating actions, the bot can prepare an impact preview before execution. It estimates affected channels, categories, roles, members, and messages, then asks for explicit confirmation when needed.

This prevents accidental mass deletion or broad server changes.

Confirmation workflow

When a plan requires approval, the bot generates a temporary confirmation ID. The user must confirm the exact ID within a short time window before the bot executes the plan.

This protects the server from accidental commands and from unauthorized confirmations by other members.

Modular action registry

The project is split into specialized action modules:

  • Server actions – list server summary, categories, channels, roles, members, bots, admins, moderators, bans, invites, webhooks, emojis, and stickers.
  • Channel actions – create, delete, rename, move, clone, archive, lock, unlock, hide, unhide, update topics, set NSFW, set slowmode, and manage permissions.
  • Cleanup actions – delete empty categories, delete uncategorized channels, delete channels by name, delete category with channels, delete empty channels, and archive inactive channels.
  • Message actions – fetch/search messages, delete selected messages, purge messages by filters, pin/unpin messages, and list pinned messages.

AI provider abstraction

The AI layer supports multiple providers through configuration:

  • Google Gemini
  • OpenAI

The active provider, model, API key environment variable, retry count, and retry delay are configured in a central config file.

Retry handling for temporary AI failures

The bot detects transient AI failures such as rate limits, timeouts, and server errors. It retries automatically and can offer an additional retry flow through a Discord reaction.

Discord permission and access checks

Only users with server administration permissions, Manage Server, or a configured owner ID can use administrative commands. Replies are sent safely, with mention parsing disabled to avoid accidental pings.

Server snapshot system

Before planning, the bot builds a structured snapshot of the guild, including:

  • guild ID and name
  • owner ID
  • categories
  • channels
  • parent category information
  • channel metadata such as topic, NSFW status, slowmode, and position
  • roles and permissions
  • member summary

This allows the AI planner to reason about real server state without inventing targets.

Tech stack

  • Node.js
  • discord.js
  • Google GenAI SDK
  • OpenAI SDK
  • dotenv
  • ES Modules

Project structure

.
├── index.js                 # Discord client, command routing, confirmation flow
├── config.js                # Bot prefix, AI provider, models, retry settings
├── ai.js                    # AI provider abstraction, structured output, retry logic
├── planner.js               # Natural language command planner and validation layer
├── planPreview.js           # Impact preview for mutating/destructive plans
├── guildSnapshot.js         # Builds a safe server snapshot for the planner
├── tools.js                 # Tool definitions, limits, defaults, and safety groups
├── errors.js                # Custom errors and Discord error formatting
└── actions/
    ├── index.js             # Action registry and plan executor
    ├── server.js            # Read-only server inspection tools
    ├── channels.js          # Channel/category management tools
    ├── cleanup.js           # Server cleanup automation tools
    ├── messages.js          # Message search, purge, and pin tools
    └── helpers.js           # Shared Discord helper functions

How it works

  1. A Discord admin sends a command using the configured prefix.
  2. The bot verifies that the user is allowed to run administrative commands.
  3. The bot builds a live snapshot of the Discord server.
  4. The AI planner converts the natural language request into a strict JSON plan.
  5. The plan is validated against known tools, IDs, limits, and safety rules.
  6. If the plan is read-only, it runs immediately.
  7. If the plan changes the server, the bot prepares a preview and requires confirmation.
  8. After confirmation, the action registry executes the plan step by step.
  9. Results or formatted errors are sent back to Discord.

Example commands

!bot listează canalele fără categorie
!bot arată un rezumat al serverului
!bot creează o categorie numită Support
!bot mută canalul general în categoria Community
!bot șterge categoriile goale
!bot arhivează canalele inactive
!bot caută mesaje care conțin discord.gg
!bot șterge ultimele 50 de mesaje din canalul curent
!bot listează moderatorii serverului

Safety features

This project includes several layers of protection:

  • Admin-only command access
  • Strict JSON schema for AI output
  • Tool allowlist
  • Unknown tool rejection
  • Snowflake ID validation
  • Known channel/category/role validation
  • Maximum plan step limits
  • Maximum explicit and dynamic target limits
  • Confirmation for mutating actions
  • Preview system for affected resources
  • Discord error formatting
  • Reply splitting to avoid Discord message length issues
  • Mentions disabled in bot replies

Environment variables

Create a .env file in the project root:

DISCORD_TOKEN=your_discord_bot_token
GEMINI_API_KEY=your_google_genai_api_key
OPENAI_API_KEY=your_openai_api_key
OWNER_ID=optional_discord_user_id

The project can be configured to use either Google Gemini or OpenAI from config.js.

Installation

npm install

If you do not already have a package.json, initialize one and install the required dependencies:

npm init -y
npm install discord.js dotenv openai @google/genai

Make sure your package.json uses ES modules:

{
  "type": "module",
  "scripts": {
    "start": "node index.js"
  }
}

Running the bot

npm start

The bot will log in to Discord using DISCORD_TOKEN and print the active AI provider/model in the console.

Discord bot requirements

Enable the required intents in the Discord Developer Portal:

  • Guilds
  • Guild Messages
  • Message Content
  • Guild Members
  • Guild Moderation
  • Guild Invites
  • Guild Message Reactions

The bot also needs the appropriate server permissions depending on the actions you want to use, such as:

  • Manage Channels
  • Manage Messages
  • Manage Roles / Permissions where applicable
  • View Audit Log where useful
  • Send Messages
  • Add Reactions
  • Read Message History

What I learned / demonstrated

This project demonstrates:

  • integrating Discord APIs with real server state
  • building an AI-assisted command planner
  • validating AI output before execution
  • designing safer automation for destructive actions
  • modular backend architecture in Node.js
  • retry handling for unstable external AI services
  • permission-aware bot development
  • structured error handling and user feedback

Future improvements

  • Add a web dashboard for reviewing plans before execution
  • Add persistent audit logs for every executed plan
  • Add role-management actions
  • Add test coverage for planner validation and action execution
  • Add localization support for English/Romanian responses
  • Add Docker support for easier deployment
  • Add database-backed confirmation and history tracking

Disclaimer

This bot can perform administrative Discord actions. Use it only in servers where you have permission to manage resources, and always review previews before confirming destructive actions.

About

AI-powered Discord administration bot with natural language commands, safe previews, confirmation flows, channel cleanup, message moderation, and multi-provider AI support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages