Documentation Index
Fetch the complete documentation index at: https://mintlify.com/disgoorg/disgo/llms.txt
Use this file to discover all available pages before exploring further.
Quickstart
This guide will walk you through creating a simple ping-pong bot that responds to messages. You’ll learn the basics of creating a DisGo client, listening for events, and interacting with Discord.Before starting, make sure you’ve installed DisGo and have a bot token from the Discord Developer Portal.
Create your first bot
Let’s build a bot that responds to “ping” with “pong” and vice versa. This example demonstrates the core concepts of DisGo: client initialization, Gateway connections, and event handling.Create the main file
Create a new file called
main.go in your project directory:main.go
This example uses the
disgo_token environment variable for the bot token. You can name it anything you prefer.Set your bot token
Set the environment variable with your bot token:Or create a
.env file and load it with a package like godotenv.Understanding the code
Let’s break down the key components of this bot:Client initialization
disgo.New()creates a new bot client with your token- Gateway intents specify which events you want to receive:
IntentGuildMessages- Receive message events in guildsIntentMessageContent- Access message content (privileged intent)
- Event listeners register functions to handle specific events
The Message Content Intent is a privileged intent. You must enable it in the Discord Developer Portal under your bot’s settings.
Gateway connection
Event handling
- The event handler receives
MessageCreateevents - We ignore messages from bots to prevent loops
- Access message data through
event.Message
Sending messages
- Use the REST client to send messages
NewMessageCreateBuilder()provides a fluent API for constructing messages- Send rich messages with embeds, components, and more
Graceful shutdown
defer client.Close()ensures cleanup when the program exits- Signal handling allows graceful shutdown with Ctrl+C
Alternative event handling patterns
DisGo offers multiple ways to handle events. Here are some alternatives:Adding more features
Now that you have a basic bot, you can extend it with more functionality:Slash commands
Add modern slash commands to your bot
Message components
Create interactive buttons and select menus
Embeds
Send rich embedded messages
Voice connections
Connect to voice channels
Common intents
Depending on your bot’s functionality, you’ll need different intents:| Intent | Purpose | Privileged |
|---|---|---|
IntentGuilds | Guild create/update/delete events | No |
IntentGuildMembers | Member join/leave/update events | Yes |
IntentGuildMessages | Message events in guilds | No |
IntentGuildMessageReactions | Reaction add/remove events | No |
IntentDirectMessages | Direct message events | No |
IntentMessageContent | Access to message content | Yes |
IntentGuildPresences | User presence updates | Yes |
Next steps
Congratulations! You’ve built your first DisGo bot. Continue learning:Basic concepts
Deep dive into DisGo’s architecture
More examples
Explore advanced examples