DisAgent is an AI agent bot that runs on Discord. It can automatically execute complex tasks using various tools (Web Search, HTTP requests, and Discord operations).
Important
This project was for a hackathon. I found running AI agents in Discord too restrictive, as it's better to allow broader operations beyond one platform. Thus, I have no plans for further updates.
- π€ AI Agent System: Completes tasks via an autonomous loop.
- π§ Tool Calling: Web search, HTTP requests, and Discord operations.
- π Multi-AI Provider Support: OpenRouter, Cerebras, Anthropic, and Google.
- π¬ Streaming Responses: Displays thinking process and execution in real-time.
- π Conversation History: Continue discussions using the
/replycommand. - β±οΈ Rate Limiting: Prevents excessive usage.
- OpenRouter: Access numerous models including Claude, GPT-4, and Gemini.
- Cerebras: High-speed Llama models.
- Anthropic: Claude 4.5 Sonnet, Claude 4.6 Opus and more.
- Google(Gemini): Gemini 3.0 Flash, Gemini 3.1 Pro, Gemini 3.1 Flash Lite and more.
- Node.js 18.x or higher
- Discord Bot Token
- API Key(s) for at least one AI provider
- Go to the Discord Developer Portal.
- Create a new application.
- In the "Bot" section, create a bot and copy the token.
- Under "OAuth2" β "URL Generator," select the following scopes:
botapplications.commands
- Select the following Bot Permissions:
- Send Messages
- Embed Links
- Read Message History
- Manage Channels
- Manage Messages
- Manage Roles
- Invite the bot to your server using the generated URL.
# Clone the repository (or copy the code)
cd DisAgent
# Install dependency packages
npm installCreate a .env file and set the following values:
# Discord Bot
DISCORD_BOT_TOKEN=your_bot_token_here
CLIENT_ID=your_application_client_id_here
DISCORD_GUILD_ID=your_guild_id_here # Optional: set for immediate command updates
# AI Providers (At least one required)
OPENROUTER_API_KEY=your_key # https://openrouter.ai/keys
CEREBRAS_API_KEY=your_key # https://inference.cerebras.ai/
ANTHROPIC_API_KEY=your_key # https://console.anthropic.com/settings/keys
GOOGLE_API_KEY=your_key # https://makersuite.google.com/app/apikey
# Tool API Keys (Optional)
GOOGLE_SEARCH_API_KEY=your_key # https://developers.google.com/custom-search/v1/overview
GOOGLE_SEARCH_ENGINE_ID=your_id # https://cse.google.com/cse/
BRAVE_SEARCH_API_KEY=your_key # https://api.search.brave.com/
# Image Related
MAX_IMAGE_BYTES=5242880 # Max image size (bytes)
MAX_IMAGE_COUNT=4 # Max images per request
OPENROUTER_IMAGE_MODEL=your_image_model_id # Uses openai/dall-e-3 if unset
# GitHub App
GITHUB_APP_ID=your_github_app_id
GITHUB_APP_PRIVATE_KEY=your_private_key_or_base64 # Escape newlines with \\n
# Settings
DEFAULT_PROVIDER=openrouter
DEFAULT_MODEL=gpt-4-turbo
RATE_LIMIT_REQUESTS_PER_MINUTE=10How to get CLIENT_ID:
- Found in the "General Information" tab of your application page in the Discord Developer Portal.
npm startStarts a new agent session.
/agent prompt:"Search for and summarize the latest AI news"
/agent prompt:"Please create a new channel" provider:anthropic
/agent prompt:"Check the weather" model:gpt-4-turbo temperature:0.5
Parameters:
prompt(Required): Request for the agent.provider(Optional): AI Provider (OpenRouter, Cerebras, Anthropic, Google).model(Optional): Model to use.temperature(Optional): Temperature parameter (0.0 - 1.0).image1toimage4(Optional): Image attachments (Up to 4).
Continues from the previous conversation.
/reply prompt:"Tell me more in detail"
Displays available commands and features.
Lists configured AI models and providers.
/list-models
Displays the conversation history for the current channel.
/history
The agent can utilize the following tools:
Searches for information on the web.
Example:
/agent prompt:"Search for the latest technology news"
Sends HTTP requests to any URL. Returns Base64 for image URLs.
Example:
/agent prompt:"Fetch https://api.github.com/repos/octocat/Hello-World"
Allows creating, updating, or deleting Discord channels, messages, and roles. Can also post images (sent as attachments).
Example:
/agent prompt:"Read the information of this channel"
/agent prompt:"Please create a new role"
Note: Discord operations require appropriate permissions.
Generates images via OpenRouter.
Posting generated images (Auto-execution by AI):
- Generate with
image_generateand get thegeneratedId. - Pass
type: "generated"in theattachmentsofcreate_messageindiscord_ops.
- External images can be attached via
type: "url".
Security: Generated images are saved locally; only images generated within the same channel can be attached.
Example:
/agent prompt:"Paint a sunset at the beach" model:gpt-4o-mini
Retrieves repository/Issue/PR/Release information using a GitHub App.
Example:
/agent prompt:"Set up GitHub integration installationId=123456 defaultRepo=owner/repo"
/agent prompt:"Show me the latest Issues"
- Thinking: The agent understands the request and creates a plan.
- Tool Execution: Automatically calls necessary tools.
- Result Analysis: Analyzes tool output and decides the next action.
- Complete or Continue: Loops until the goal is achieved.
- Summary: Summarizes and shares the final results.
Available models can be configured in config/models.json:
{
"providers": {
"openrouter": {
"name": "OpenRouter",
"models": [
{
"id": "anthropic/claude-3.5-sonnet",
"name": "Claude 3.5 Sonnet",
"supportsTools": true,
"context": 200000
}
]
}
}
}Set rate limits in .env:
RATE_LIMIT_REQUESTS_PER_MINUTE=10Default is 10 requests per minute.
- Create a GitHub App and install it with necessary (read) permissions.
- Set
GITHUB_APP_IDandGITHUB_APP_PRIVATE_KEYin.env. - Use
set_configwithin thegithub_readtool via/agentto save theinstallationIdanddefaultRepofor each guild.
- Verify the Discord Bot Token is correct.
- Ensure the bot is invited to the server.
- Check if the bot has been granted the necessary permissions.
- Verify the API key is correct.
- Ensure the API key has the correct permissions.
- Check if you have reached API usage limits (rate limits).
- Check if the bot is running correctly.
- Confirm that commands are registered (check the logs at startup).
DisAgent/
βββ src/
β βββ bot.js # Main Discord bot file
β βββ commands/ # Slash commands
β β βββ agent.js
β β βββ reply.js
β β βββ help.js
β β βββ list-models.js
β β βββ history.js
β βββ agent/ # Agent system
β β βββ agent.js
β β βββ prompts.js
β βββ providers/ # AI providers
β β βββ base.js
β β βββ openrouter.js
β β βββ cerebras.js
β β βββ anthropic.js
β β βββ google.js
β β βββ index.js
β βββ tools/ # Tools
β β βββ base.js
β β βββ web-search.js
β β βββ fetch.js
β β βββ discord-ops.js
β β βββ index.js
β βββ streaming/ # Streaming handling
β β βββ stream-handler.js
β βββ utils/ # Utilities
β β βββ logger.js
β β βββ message-formatter.js
β βββ rate-limit.js # Rate limiting
βββ config/
β βββ models.json # Model settings
βββ .env # Environment variables (Copy from .env.example)
βββ .env.example # Env variable template
βββ package.json
βββ README.md
- Never share your
.envfile. - Do not include the
.envfile in public repositories like GitHub. - It is recommended to add
.envto your.gitignore. - Keep bot permissions to the minimum necessary.
Please open an Issue for bug reports or feature requests.
ISC
If you encounter any issues, please open an Issue.
Note: This bot is an experimental project. Use with caution for critical tasks.