A production-grade .NET 8 Discord bot for Azure DevOps engineering workflows.
It combines two operating modes:
- Reference Resolver in normal chat messages (
#workItem,!pullRequest) - Structured Slash Commands for repeatable team communication
- Read-only Azure DevOps integration (work items + pull requests)
- Compact, non-spam Discord responses
- Multi-repository PR resolution by PR ID at project scope
- In-memory caching and resilient HTTP retry policy
- Duplicate-event protection to avoid repeated bot messages
- Command-based workflow messaging with consistent formatting
When a user posts a message containing Azure DevOps references, the bot enriches it automatically.
#1234-> Work Item lookup!5678-> Pull Request lookup
Behavior:
- Handles multiple references in one message
- Deduplicates repeated IDs in the same message
- Sends a single compact bot response per source message
Creates a structured review request.
Options:
task(required): work item IDprs(required): PR IDs (comma/space separated)reviewers(required): mentions/names/rolesnote(optional): context
Formatting:
- Singular/plural-aware labels (
Reviewer/Reviewers,PR/PRs) - Repository shown in PR heading
- Leading task/repo prefixes in PR titles cleaned for readability
Publishes a standardized “work started” announcement.
Options:
task(required): work item IDnote(optional): context
Includes:
- announcer
- task link + italicized title
- type, priority, estimation, area
Publishes a task assignment message.
Options:
task(required): work item IDassignee(optional): person/rolenote(optional): context
Assignee behavior:
- If
assigneeis provided, that value is used - Otherwise, assignee is pulled from the Azure DevOps task
- If neither exists, assignee line is omitted
Authorization behavior (applies only to /assigntask):
- Layer 1 (Discord native): restrict command access by role/user from Discord server command permissions
- Layer 2 (bot enforcement): optional allowlists in configuration
AllowedRoleIdsCsvAllowedUserIdsCsv
- If both allowlists are empty, bot-side restriction is disabled and Discord native permissions control access
- If any allowlist is populated, requester must match allowed user IDs or role IDs
Creates a structured bug report and posts it to a dedicated bug-report channel.
Slash command metadata options:
title(required): short summaryarea(required): frontend/backend/locale_translations/devopsenvironment(required): development/qas/productionplatform(required): windows/osx/ios/androidbrowser(optional): chrome/firefox/safari/opera/brave/otherversion(required): app/build versioninstance(required): customer/instance identifiercheck_dedupe(optional, defaulttrue): pre-check duplicates before modal opensattachment(optional): single evidence filetag(optional): mention target (for example@frontend)note(optional): extra context
Modal inputs (multiline):
- Steps to Reproduce (required)
- Expected Behavior (required)
- Actual Behavior (required)
Duplicate-detection behavior:
- Pre-modal dedupe: metadata-level check; if duplicate found, modal does not open
- Post-modal dedupe: full-content check (includes steps/expected/actual)
- Exact and fuzzy matching are both used
Discord:BugReporting options:
ChannelId: target bug-report channel idDedupeSimilarityThreshold: fuzzy similarity threshold (default0.60)DedupeMaxCandidates: max recent records checked for fuzzy dedupe (default300)
Quick guidance:
- Lower threshold => more aggressive duplicate detection (more false positives)
- Higher threshold => stricter matching (more false negatives)
Current reportbug constraints:
- Modal fields are constrained by Discord embed limits when rendered:
- each embed field value max
1024chars - long content is auto-truncated with
…(truncated)
- each embed field value max
- Slash command attachment supports one file per bug report in current implementation
- Discord slash commands do not support multi-file upload in one option
Program.cs- host bootstrap, DI, config, logging, HTTP resilienceServices/DiscordBotService.cs- Discord gateway/events, commands, message compositionServices/AzureDevOpsService.cs- Azure DevOps REST client + cachingServices/MessageParser.cs- high-performance reference parsingModels/*- options and domain recordsUtils/RegexPatterns.cs- compiled regex patternstests/discord-chatbot.Tests/*- parser unit tests
- .NET SDK 8+
- Discord bot token
- Azure DevOps PAT
Official setup references:
- Discord app/bot foundation: Discord Bots & Companion Apps
- OAuth scopes and bot permissions: OAuth2 and Permissions
- Permission model details: Discord Permissions Reference
- Azure DevOps PAT lifecycle: Use personal access tokens (Microsoft Learn)
Azure DevOps PAT minimum scopes:
- Work Items: Read
- Code: Read
Use either appsettings.json or environment variables.
{
"Discord": {
"Token": "YOUR_DISCORD_BOT_TOKEN",
"GuildId": null,
"BugReporting": {
"ChannelId": null,
"DedupeSimilarityThreshold": 0.60,
"DedupeMaxCandidates": 300
},
"CommandAuthorization": {
"AssignTask": {
"AllowedRoleIdsCsv": "",
"AllowedUserIdsCsv": "",
"UnauthorizedMessage": "you are not authorized to assign tasks to others."
}
}
},
"AzureDevOps": {
"Organization": "your-org",
"Project": "your-project",
"PersonalAccessToken": "YOUR_PAT"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}| Setting | Environment Variable |
|---|---|
| Discord token | Discord__Token |
| Discord guild id (optional) | Discord__GuildId |
| Bug report channel id | Discord__BugReporting__ChannelId |
| Bug dedupe threshold | Discord__BugReporting__DedupeSimilarityThreshold |
| Bug dedupe max candidates | Discord__BugReporting__DedupeMaxCandidates |
| AssignTask allowed role IDs CSV (optional) | Discord__CommandAuthorization__AssignTask__AllowedRoleIdsCsv |
| AssignTask allowed user IDs CSV (optional) | Discord__CommandAuthorization__AssignTask__AllowedUserIdsCsv |
| AssignTask unauthorized message (optional) | Discord__CommandAuthorization__AssignTask__UnauthorizedMessage |
| ADO organization | AzureDevOps__Organization |
| ADO project | AzureDevOps__Project |
| ADO PAT | AzureDevOps__PersonalAccessToken |
| Log level | Logging__LogLevel__Default |
dotnet restore
dotnet build ./discord-chatbot.slnx
dotnet run --project ./discord-chatbot.csprojRun tests:
dotnet test ./tests/discord-chatbot.Tests/discord-chatbot.Tests.csproj- Create a Discord application and bot user:
- Enable Message Content Intent
- Intent behavior reference: Application Resource Flags
- Invite bot with permissions:
- View Channels
- Read Message History
- Send Messages
- Embed Links
- Invite/permission flow reference: OAuth2 and Permissions
- (Recommended) set
Discord:GuildIdfor fast command propagation
Azure DevOps token guidance:
- Create and scope PATs: Use personal access tokens
- Organizational PAT policy controls: Manage PATs with policies
Docker references:
- Create
.envfrom template - Fill values
- Start
docker compose up -d --buildLogs:
docker compose logs -f discord-azure-botStop:
docker compose downLinux/macOS (bash/zsh):
export DISCORD_TOKEN="<token>"
export DISCORD_GUILD_ID="<guild-id>"
export BUGREPORT_CHANNEL_ID="<bug-report-channel-id>"
export BUGREPORT_DEDUPE_THRESHOLD="0.60"
export BUGREPORT_DEDUPE_MAX_CANDIDATES="300"
export ASSIGNTASK_ALLOWED_ROLE_IDS="<role-id-1,role-id-2>"
export ASSIGNTASK_ALLOWED_USER_IDS="<user-id-1,user-id-2>"
export ASSIGNTASK_UNAUTHORIZED_MESSAGE="you are not authorized to assign tasks to others."
export AZDO_ORGANIZATION="<org>"
export AZDO_PROJECT="<project>"
export AZDO_PAT="<pat>"
export LOG_LEVEL="Information"
docker compose up -d --buildWindows PowerShell:
$env:DISCORD_TOKEN="<token>"
$env:DISCORD_GUILD_ID="<guild-id>"
$env:BUGREPORT_CHANNEL_ID="<bug-report-channel-id>"
$env:BUGREPORT_DEDUPE_THRESHOLD="0.60"
$env:BUGREPORT_DEDUPE_MAX_CANDIDATES="300"
$env:ASSIGNTASK_ALLOWED_ROLE_IDS="<role-id-1,role-id-2>"
$env:ASSIGNTASK_ALLOWED_USER_IDS="<user-id-1,user-id-2>"
$env:ASSIGNTASK_UNAUTHORIZED_MESSAGE="you are not authorized to assign tasks to others."
$env:AZDO_ORGANIZATION="<org>"
$env:AZDO_PROJECT="<project>"
$env:AZDO_PAT="<pat>"
$env:LOG_LEVEL="Information"
docker compose up -d --build- Uses retry policy for transient HTTP failures and rate-limit responses
- Uses in-memory cache for ADO entity lookups (TTL-based)
- Prevents duplicate processing of the same Discord message event
- Keeps command and resolver outputs concise for channel readability
MIT License. See LICENSE.