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.
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:
- Productivity – administrators can describe what they want in natural language.
- Safety – destructive or mutating actions require validation, preview, and confirmation.
- 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.
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”
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
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.
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.
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.
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.
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.
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.
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.
- Node.js
- discord.js
- Google GenAI SDK
- OpenAI SDK
- dotenv
- ES Modules
.
├── 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- A Discord admin sends a command using the configured prefix.
- The bot verifies that the user is allowed to run administrative commands.
- The bot builds a live snapshot of the Discord server.
- The AI planner converts the natural language request into a strict JSON plan.
- The plan is validated against known tools, IDs, limits, and safety rules.
- If the plan is read-only, it runs immediately.
- If the plan changes the server, the bot prepares a preview and requires confirmation.
- After confirmation, the action registry executes the plan step by step.
- Results or formatted errors are sent back to Discord.
!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 serveruluiThis 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
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_idThe project can be configured to use either Google Gemini or OpenAI from config.js.
npm installIf 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/genaiMake sure your package.json uses ES modules:
{
"type": "module",
"scripts": {
"start": "node index.js"
}
}npm startThe bot will log in to Discord using DISCORD_TOKEN and print the active AI provider/model in the console.
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
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
- 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
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.