A Discord chatbot that uses Ollama to run AI models locally. Built with .NET 8 and Discord.NET.
- @Mention responses - Mention the bot in any channel to chat
- Direct message support - DM the bot without needing to @mention
- Per-user conversation memory - Each user has their own conversation context
- Customizable personality - Configure the system prompt to change bot behavior
- Fully local - No API costs, runs entirely on your machine
- .NET 8 SDK
- Ollama installed and running
- A Discord bot token (Discord Developer Portal)
-
Clone the repository
git clone https://github.com/yourusername/DiscordOllamaBot.git cd DiscordOllamaBot -
Pull the Ollama model
ollama pull qwen3:4b
-
Configure the bot
Edit
appsettings.jsonwith your Discord bot token:{ "Discord": { "Token": "YOUR_BOT_TOKEN" } } -
Enable Message Content Intent
In the Discord Developer Portal:
- Select your application → Bot → Privileged Gateway Intents
- Enable Message Content Intent
-
Run the bot
dotnet run
| Setting | Default | Description |
|---|---|---|
Discord:Token |
- | Your Discord bot token (required) |
Ollama:Endpoint |
http://localhost:11434 |
Ollama API endpoint |
Ollama:Model |
qwen3:4b |
Ollama model to use |
Ollama:SystemPrompt |
You are a helpful Discord assistant... |
Bot personality/instructions |
Conversation:MaxHistory |
20 |
Max messages to remember per user |
DiscordOllamaBot/
├── Program.cs # Entry point & DI setup
├── appsettings.json # Configuration
├── Models/
│ ├── BotConfiguration.cs # Config POCOs
│ └── ConversationContext.cs # User conversation state
├── Services/
│ ├── OllamaService.cs # Ollama API integration
│ └── ConversationService.cs # Per-user history management
└── Handlers/
└── MessageHandler.cs # Discord message processing
In a server channel:
@BotName What is the capital of France?
In direct messages:
What is the capital of France?
The bot remembers your conversation history, so you can have multi-turn conversations.
You can use any model available in Ollama. Update appsettings.json:
{
"Ollama": {
"Model": "llama3:8b"
}
}Popular options:
qwen3:4b- Fast, good for general chatllama3:8b- Balanced performancemistral:7b- Great reasoning capabilitiescodellama:7b- Optimized for code
MIT