- Natural Language: Understands complex Discord-related requests in natural language
- Dynamic Generation: Generates and executes Discord.js v14 code on-the-fly to perform any Discord operation
- Multi-Step Operations: Performs complex tasks by breaking them down into steps, enabling sophisticated and unique commands that go beyond traditional bot capabilities
- Extensible Tooling: Custom built-in GIF tool, and ability to easily add as many tools as needed
- Conversation Context: Maintains conversation history through Discord reply chains
- Configurable Limits: Customizable iteration limits and conversation depth
- The bot executes LLM-generated code in an unsandboxed environment
- The current implementation relies on AI alignment + system prompting to prevent malicious code generation. While this gaurdrail works effectively for most cases with a SotA model, this is not a production ready security solution. In production, code should ONLY be executed in a fully isolated sandbox environment. side note: anecdotally, the bot is very safe
@DARVIS ban Henry for spamming
@DARVIS send a funny gif
@DARVIS stylize this server's channel names and categories to have a kawaii theme
@DARVIS DM a philosophical quote to everyone with the philosophy role
@DARVIS who has sent the most messages in this channel?
@DARVIS @ a random user in the server
@DARVIS show me the member count of this server
@DARVIS list all users who joined in the last 24h
@DARVIS fix this channel's name to follow the same format as the other channels in this category
- Node.js (v16+)
- A Discord Bot Token (with intents enabled)
- An LLM API Key (for any standard completions API; e.g. OpenAI, Anthropic, xAI)
git clone https://github.com/braindead-dev/DARVIS
cd Darvis
npm i
- Go to the Discord Developer Portal
- Create a new application
- Navigate to the "Bot" section
- Create a bot and copy the token
- Enable the following privileged gateway intents:
- Message Content Intent (required for reading message content)
- Server Members Intent (required for member operations)
Create a .env
file in the root directory that follows the .env.template
# Development
npm run dev
# Production
npm start
The bot's behavior is controlled through src/core/config.ts
. Here's what each setting means:
Setting | Type | Description | Default |
---|---|---|---|
apiEndpoint |
string | LLM API endpoint URL | OpenAI's GPT API |
model |
string | LLM model to use | gpt-4.1 |
systemPrompt |
function | Generates the system prompt for the LLM | Detailed Discord bot instructions |
fallbackMessage |
string | Message sent when max iterations reached | Error message |
maxIterations |
number | Maximum LLM calls per request | 5 |
maxConversationDepth |
number | Max messages to include in context | 10 |
Discord Message → Filter (mentions bot?) → Build Context → LLM Processing → Execute Actions → Respond
-
Message Reception (
src/index.ts
)- Bot receives a message in Discord
- Filters out bot messages and non-mentions
- Shows typing indicator
-
Context Building (
src/core/agent.ts#buildConversationHistory
)- Traverses reply chain backwards up to
maxConversationDepth
- Builds conversation history with user info and roles
- Formats messages for LLM consumption
- Traverses reply chain backwards up to
-
LLM Processing Loop (
src/core/agent.ts#runAgent
)- Sends conversation + system prompt to LLM
- LLM decides whether to:
- Respond directly with text
- Execute Discord.js code
- Search for GIFs
- Up to
maxIterations
loops allowed
-
Code Execution (
src/tools/executor.ts
)- Creates sandboxed environment
- Provides access to
client
andmessage
objects - Executes generated Discord.js code
- Returns results back to LLM
-
Response Delivery
- Attempts to reply to original message
- Falls back to new message if reply fails
- Handles deleted messages gracefully
The bot uses a tool-based architecture:
execute_discord_js_code
: Executes Discord.js operationssearch_gif
: Searches and posts GIFs- Tools are defined with strict schemas for the LLM
- Create a new tool file in
src/tools/
- Export a tool definition object and execution function
- Import and add to the tools array in
src/core/agent.ts
Example tool structure:
export const myTool = {
type: 'function' as const,
function: {
name: 'my_tool',
description: 'Description of what the tool does',
parameters: {
type: 'object',
properties: {
param1: { type: 'string', description: 'Parameter description' }
},
required: ['param1']
}
}
};
Always open for contributions!! Feel free to submit a PR