Skip to content

@tank/go-discord-bot

1.0.0

Build Discord bots in Go with discordgo, arikawa, or disgo. Covers slash commands, handler patterns, components, embeds, intents, events, state, database (pgx, entgo), voice (dgvoice, dca), goroutine safety, sharding, deployment. Triggers: discord bot go, discordgo, arikawa, disgo, golang discord bot, slash command go, discord gateway go, discord voice go, discord embed go, discord button go, discord modal go, discord bot docker go, dgvoice, discord sharding go.


name: go-discord-bot description: | Build Discord bots in Go using discordgo, arikawa, or disgo. Covers library selection, project scaffolding, slash commands and handler patterns, message components (buttons, select menus, modals), gateway intents, state and database integration (pgx, entgo, Redis), voice and audio (dgvoice, dca), goroutine safety, sharding, and deployment. Synthesizes discordgo v0.29.0, arikawa v3.6.0, disgo docs, and production patterns from YAGPDB, automuteus, CJ, ken, ops-bot-iii.

Trigger phrases: "discord bot go", "go discord", "discordgo", "arikawa", "disgo", "golang discord bot", "slash command go", "discord gateway go", "discord intents go", "discord voice go", "discord music bot go", "discord embed go", "discord button go", "discord modal go", "discord select menu go", "discord bot golang", "dgvoice", "discord sharding go", "discord deployment go", "discord bot docker go", "discord bot systemd go", "go discord slash command", "discordgo handler", "discordgo interaction"

Go Discord Bot Development

Build Discord bots in Go for simplicity and concurrency. The ecosystem centers on three libraries: discordgo (low-level, dominant), arikawa (typed, modular), and disgo (modern, API v10). Most bots use discordgo.

Core Philosophy

  1. discordgo is the default — Use discordgo for all new bots unless you need typed snowflakes (arikawa) or API v10 (disgo). Largest community, most examples, most Stack Overflow answers.
  2. Slash commands first — Prefer slash commands over message-based commands. Message content requires the privileged MESSAGE_CONTENT intent, which needs Discord verification at 100+ guilds.
  3. Goroutine safety matters — discordgo fires each handler in its own goroutine. Protect shared state with sync.RWMutex, wrap handlers with recover() because panics in goroutines are silent and fatal.
  4. Respect the 3-second deadline — Discord requires an interaction response within 3 seconds. For slow operations, always defer first with InteractionResponseDeferredChannelMessageWithSource, then edit.
  5. Intents are permissions — Only request gateway intents the bot needs. Privileged intents (GUILD_MEMBERS, MESSAGE_CONTENT, PRESENCES) require Discord Developer Portal approval at 100+ guilds.

Quick-Start

"I want to build a Discord bot from scratch"

StepActionReference
1Choose library (discordgo recommended)references/library-selection.md
2Scaffold project (go.mod, main.go, .env)references/project-setup.md
3Define slash commands and handlersreferences/commands-and-interactions.md
4Configure gateway intentsreferences/event-handling.md
5Add database and shared statereferences/state-and-database.md
6Add voice support (if needed)references/voice-and-audio.md
7Deploy with Docker or systemdreferences/deployment-and-ops.md

"I need to add a slash command"

StepAction
1Define *discordgo.ApplicationCommand with name, description, options
2Add handler to commandHandlers map
3Register via s.ApplicationCommandCreate or ApplicationCommandBulkOverwrite
4Route in InteractionCreate handler by i.ApplicationCommandData().Name
-> See references/commands-and-interactions.md

"I need buttons, select menus, or modals"

StepAction
1Build components with discordgo.Button, discordgo.SelectMenu, or discordgo.TextInput
2Wrap in discordgo.ActionsRow, send via InteractionRespond
3Handle clicks via InteractionMessageComponent or InteractionModalSubmit
4Route by i.MessageComponentData().CustomID
-> See references/components-and-modals.md

"I want to add voice/music support"

StepAction
1Set IntentGuildVoiceStates intent
2Join channel with s.ChannelVoiceJoin(guildID, channelID, false, true)
3Encode audio to Opus via dgvoice/dca + ffmpeg
4Send frames via vc.OpusSend <- opusFrame
-> See references/voice-and-audio.md

Decision Trees

Library Selection

SignalUse
New bot, want to ship fastdiscordgo
Need typed snowflakes, context.Context, pluggable statearikawa
Need Discord API v10 featuresdisgo
Need chi-style interaction routingdisgo handler.Mux
Need typed command routing with struct tagsarikawa cmdroute

Database Selection

ScaleUse
Prototype / small botSQLite via database/sql
Production / growing botPostgreSQL via pgxpool
Type-safe ORMentgo (code-generated)
Multi-shard shared stateRedis (go-redis)
No persistence neededIn-memory (sync.Map)

Intent Selection

FeatureRequired Intents
Slash commands onlyIntentsGuilds (minimal)
Basic guild eventsIntentsAllWithoutPrivileged (default)
Read message content+ IntentMessageContent (privileged)
Welcome messages+ IntentGuildMembers (privileged)
Voice bot+ IntentGuildVoiceStates
Status tracking+ IntentGuildPresences (privileged)

Anti-Patterns

Don'tDo InsteadWhy
Use disgordUse discordgo, arikawa, or disgodisgord is archived, targets API v8
Request IntentsAllRequest only needed intentsFails verification at 100+ guilds
Block in event handlersUse goroutines for slow workBlocks all event processing if SyncEvents=true
Ignore panics in handlersWrap with recover() + debug.Stack()Panics in goroutines crash silently
Respond after 3 secondsDefer first, then edit responseInteraction expires, user sees error
Use sync.Mutex on Bot struct fieldsUse sync.RWMutexReaders don't need to block each other
Register guild commands in productionUse global commands or BulkOverwriteGuild commands are for development only
Skip interaction error responsesAlways respond, even with error messageSilent failures confuse users

Reference Files

FileContents
references/library-selection.mddiscordgo vs arikawa vs disgo decision matrix, go.mod configs, companion packages, migration notes
references/project-setup.mdDirectory structure (simple and production), main.go bootstrapping, configuration, .env handling, Bot struct pattern
references/commands-and-interactions.mdSlash commands, handler patterns (map dispatch, interface, cmdroute, ken), parameter types, autocomplete, subcommands, permissions, embeds
references/components-and-modals.mdButtons, select menus, modals, Components V2, component routing by CustomID, type assertions
references/event-handling.mdGateway intents (standard and privileged), event handler registration, common event types, state cache, interaction type routing
references/state-and-database.mdBot struct pattern, database integration (pgx, sqlx, entgo, GORM), Redis, in-memory state, background goroutines, context propagation
references/voice-and-audio.mddiscordgo VoiceConnection, OpusSend/OpusRecv, dgvoice/dca helpers, arikawa voice, ffmpeg pipeline, queue management
references/deployment-and-ops.mdDocker multi-stage builds, systemd services, structured logging (slog/zap), error handling, graceful shutdown, goroutine safety, sharding, CI/CD

Command Palette

Search skills, docs, and navigate Tank