discord.go

module
v0.11.5-coffee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: Apache-2.0

README

discord.go

discord.go

A typed Go library for building Discord applications.
Low-level Discord API foundation and high-level bot facade.

CI Go Reference Go Report Card Discord API v10 Go Version Version License


Why choose discord.go?

  • Two-layer architecture. A typed low-level protocol/REST foundation and a high-level bot facade with commands, middleware, collectors, and lifecycle management. Use the facade for application code, drop to the low-level API for protocol work.
  • Gateway v10 with sharding. Dispatch, heartbeat, reconnect, resume, zlib-stream compression, multi-shard support with concurrency buckets, and automatic shard count detection.
  • Voice with DAVE. WebSocket, UDP, RTP, AES-256-GCM transport encryption, Opus frame handling, and DAVE/MLS end-to-end encryption support.
  • Components V2. Full support for Discord's Components V2 message model including containers, media galleries, separators, and section components.
  • Typed throughout. Every REST resource, gateway event, and interaction type has a typed Go model. Nullable fields use pointers where omission differs from null.
  • Production-oriented. Rate limiting with bucket hashing, invalid-request tracking to prevent Cloudflare bans, audit-log reasons, multipart uploads, and context-aware cancellation on all REST calls.

Installation

go get github.com/discord-go/discord.go

Requires Go 1.26 or newer. The library targets Discord API v10.

Quick Start

package main

import (
    "log"
    "os"

    "github.com/discord-go/discord.go/bot"
    "github.com/discord-go/discord.go/intents"
)

func main() {
    token := os.Getenv("DISCORD_TOKEN")
    if token == "" {
        log.Fatal("DISCORD_TOKEN is required")
    }

    router := bot.NewRouter()
    router.Command("ping", "Check bot status", func(ctx *bot.InteractionContext) {
        if err := ctx.Reply("Pong!"); err != nil {
            log.Printf("reply: %v", err)
        }
    })

    client := bot.New(token,
        bot.WithIntents(intents.Guilds),
        bot.WithRouter(router),
    )
    if err := client.Run(); err != nil {
        log.Fatal(err)
    }
}

Documentation

The complete documentation site is at discord-go.github.io/discord.go.

Start with the high-level guides for application code or the low-level guides for protocol and REST work. Runnable examples are organized under docs/examples/.

API reference is available on pkg.go.dev.

See the FAQ and Troubleshooting pages for common questions and solutions.

Development

go test ./...
go test -race ./...
go vet ./...

Nested example modules can be tested independently from their directories. See CONTRIBUTING.md before opening a pull request.

Security

Never commit bot tokens, OAuth client secrets, webhook tokens, database credentials, or generated coverage and build artifacts. Report security issues privately via GitHub's security advisory system rather than opening a public issue. See the security policy for details.

License

This project is licensed under the Apache License 2.0.

Directories

Path Synopsis
Package application provides Discord application and team structures.
Package application provides Discord application and team structures.
Package auditlog provides structures and constants for Discord's audit log.
Package auditlog provides structures and constants for Discord's audit log.
Package cache provides a caching system for discord.go.
Package cache provides a caching system for discord.go.
Package cdn builds Discord CDN and media-proxy asset URLs.
Package cdn builds Discord CDN and media-proxy asset URLs.
Package channels provides types for interacting with Discord channels.
Package channels provides types for interacting with Discord channels.
Package client provides the main entry point for the discord.go library.
Package client provides the main entry point for the discord.go library.
Package components provides structures and functions for Discord Message Components.
Package components provides structures and functions for Discord Message Components.
docs
examples/code/interaction_server command
Package main demonstrates a Discord interaction HTTP server using interactions.Server, which verifies the Ed25519 signature and timestamp freshness of every incoming request automatically.
Package main demonstrates a Discord interaction HTTP server using interactions.Server, which verifies the Ed25519 signature and timestamp freshness of every incoming request automatically.
examples/code/moderation command
Package main demonstrates a moderation bot built using the discord.go framework.
Package main demonstrates a moderation bot built using the discord.go framework.
examples/code/ping command
Package main demonstrates a simple ping/pong Discord bot built using the discord.go framework.
Package main demonstrates a simple ping/pong Discord bot built using the discord.go framework.
examples/code/slash_commands command
Package main demonstrates how to create, register, and handle Discord slash commands using the discord.go framework.
Package main demonstrates how to create, register, and handle Discord slash commands using the discord.go framework.
examples/code/v2_components command
discord.go code
discord.go code
examples/code/v2_template command
discord.go code
discord.go code
Package events provides structures for Discord gateway events.
Package events provides structures for Discord gateway events.
Package gateway provides the Discord gateway API implementation.
Package gateway provides the Discord gateway API implementation.
Package guilds provides types and functions for interacting with Discord Guilds.
Package guilds provides types and functions for interacting with Discord Guilds.
Package http provides HTTP client utilities for interacting with the Discord API.
Package http provides HTTP client utilities for interacting with the Discord API.
Package intents provides constants and methods for Discord intents.
Package intents provides constants and methods for Discord intents.
Package interactions provides structures and functions for Discord's Interactions API.
Package interactions provides structures and functions for Discord's Interactions API.
internal
backoff
Package backoff provides a reusable exponential backoff calculator with jitter.
Package backoff provides a reusable exponential backoff calculator with jitter.
bucket
Package bucket provides route hash calculation for Discord rate limit buckets.
Package bucket provides route hash calculation for Discord rate limit buckets.
compression
Package compression provides zlib stream decompression helpers for Gateway payloads.
Package compression provides zlib stream decompression helpers for Gateway payloads.
endpoints
Package endpoints provides Discord API endpoint URL construction helpers.
Package endpoints provides Discord API endpoint URL construction helpers.
sync
Package sync provides a KeyedMutex that locks per-key.
Package sync provides a KeyedMutex that locks per-key.
Package json provides a wrapper around the standard encoding/json package.
Package json provides a wrapper around the standard encoding/json package.
Package messages provides types and utilities for Discord messages.
Package messages provides types and utilities for Discord messages.
Package oauth2 provides typed helpers for Discord OAuth2 flows.
Package oauth2 provides typed helpers for Discord OAuth2 flows.
Package permissions provides utilities for working with Discord permission bitfields.
Package permissions provides utilities for working with Discord permission bitfields.
Package ratelimit provides rate limiting functionality for Discord API.
Package ratelimit provides rate limiting functionality for Discord API.
Package rest provides a client for interacting with the Discord REST API.
Package rest provides a client for interacting with the Discord REST API.
Package roles provides types and functions for interacting with Discord roles.
Package roles provides types and functions for interacting with Discord roles.
Package snowflake provides a type and utilities for handling Discord snowflakes.
Package snowflake provides a type and utilities for handling Discord snowflakes.
Package storage contains small persistence primitives that can back bot settings, statistics, moderation records, and other application state.
Package storage contains small persistence primitives that can back bot settings, statistics, moderation records, and other application state.
Package users provides structures and constants related to Discord users, members, and presences.
Package users provides structures and constants related to Discord users, members, and presences.
Package voice provides types and a client for managing Discord voice connections.
Package voice provides types and a client for managing Discord voice connections.
Package webhook provides types and functionality for working with Discord webhooks.
Package webhook provides types and functionality for working with Discord webhooks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL