Skip to main content

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.

Creating messages is one of the most common tasks in Discord bot development. DisGo provides a powerful and flexible API for crafting everything from simple text messages to rich embeds with attachments.

Basic message creation

The simplest way to send a message:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.MessageCreate{
        Content: "Hello, Discord!",
    },
)

Using the builder pattern

DisGo supports a fluent builder pattern for creating messages:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("Hello!").
        WithEphemeral(true),
)

Message components

All the fields you can use when creating a message:
discord.MessageCreate{
    Content:    "Message text",
    TTS:        false,
    Embeds:     []discord.Embed{},
    Components: []discord.LayoutComponent{},
    Files:      []*discord.File{},
    AllowedMentions: &discord.AllowedMentions{},
    MessageReference: &discord.MessageReference{},
    Flags:      discord.MessageFlagsNone,
}

Embeds

Embeds allow you to create rich, formatted messages:

Basic embed

embed := discord.NewEmbedBuilder().
    SetTitle("Embed Title").
    SetDescription("This is a description").
    SetColor(0x5865F2).
    Build()

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().WithEmbeds(embed),
)

Complete embed example

embed := discord.NewEmbedBuilder().
    SetTitle("Discord Bot Tutorial").
    SetDescription("Learn how to create Discord bots").
    SetURL("https://example.com").
    SetColor(0x5865F2).
    SetAuthor("Bot Author", "https://example.com", "https://example.com/avatar.png").
    SetThumbnail("https://example.com/thumbnail.png").
    SetImage("https://example.com/image.png").
    AddField("Field 1", "Value 1", true).
    AddField("Field 2", "Value 2", true).
    AddField("Field 3", "Value 3", false).
    SetFooter("Footer Text", "https://example.com/footer.png").
    SetTimestamp(time.Now()).
    Build()

Multiple embeds

You can send up to 10 embeds per message:
embed1 := discord.NewEmbedBuilder().
    SetTitle("First Embed").
    SetColor(0xFF0000).
    Build()

embed2 := discord.NewEmbedBuilder().
    SetTitle("Second Embed").
    SetColor(0x00FF00).
    Build()

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().WithEmbeds(embed1, embed2),
)

Files and attachments

Sending a file

import "os"

file, err := os.Open("image.png")
if err != nil {
    return err
}
defer file.Close()

_, err = client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("Here's an image!").
        AddFile("image.png", "A cool image", file),
)

Sending from bytes

import "bytes"

data := []byte("Hello from a file!")

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        AddFile("data.txt", "Text file", bytes.NewReader(data)),
)

Embedding files in embeds

Reference uploaded files in embed images:
file, _ := os.Open("image.png")
defer file.Close()

embed := discord.NewEmbedBuilder().
    SetTitle("Image Embed").
    SetImage("attachment://image.png").
    Build()

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithEmbeds(embed).
        AddFile("image.png", "", file),
)

Message components

Add interactive components to your messages:

Buttons

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("Click a button!").
        AddActionRow(
            discord.NewPrimaryButton("Primary", "button_1"),
            discord.NewSecondaryButton("Secondary", "button_2"),
            discord.NewSuccessButton("Success", "button_3"),
            discord.NewDangerButton("Danger", "button_4"),
        ),
)

Select menus

_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("Choose an option:").
        AddActionRow(
            discord.NewStringSelectMenu(
                "select_menu",
                "Select something...",
                discord.NewStringSelectMenuOption("Option 1", "value_1"),
                discord.NewStringSelectMenuOption("Option 2", "value_2"),
                discord.NewStringSelectMenuOption("Option 3", "value_3"),
            ),
        ),
)

Replying to messages

Create a reply to another message:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("This is a reply!").
        WithMessageReferenceByID(messageID),
)

Message flags

Ephemeral messages

Only visible to the user who triggered the interaction:
event.CreateMessage(discord.MessageCreate{
    Content: "Only you can see this!",
    Flags:   discord.MessageFlagEphemeral,
})

Suppress embeds

Prevent automatic embed generation:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("https://example.com").
        WithSuppressEmbeds(true),
)

Suppress notifications

Send a message without pinging anyone:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("@everyone important update!").
        WithSuppressNotifications(true),
)

Allowed mentions

Control what mentions are allowed in your message:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.MessageCreate{
        Content: "@everyone Hello @user!",
        AllowedMentions: &discord.AllowedMentions{
            Parse: []discord.AllowedMentionType{
                discord.AllowedMentionTypeUsers,
            },
            // Don't allow @everyone
        },
    },
)

Disable all mentions

AllowedMentions: &discord.AllowedMentions{
    Parse: []discord.AllowedMentionType{},
}

Allow specific users

AllowedMentions: &discord.AllowedMentions{
    Users: []snowflake.ID{userID1, userID2},
}

Text-to-speech (TTS)

Send a message that will be read aloud:
_, err := client.Rest.CreateMessage(
    channelID,
    discord.NewMessageCreate().
        WithContent("This will be spoken!").
        WithTTS(true),
)
Use TTS sparingly as it can be disruptive to users.

Message formatting

Discord supports Markdown formatting:
Content: "**bold** *italic* ***bold italic***"

Complete example

Here’s a comprehensive example combining multiple features:
package main

import (
    "bytes"
    "context"
    "time"

    "github.com/disgoorg/disgo"
    "github.com/disgoorg/disgo/bot"
    "github.com/disgoorg/disgo/discord"
    "github.com/disgoorg/disgo/events"
)

func handleCommand(event *events.ApplicationCommandInteractionCreate) {
    // Create a rich embed
    embed := discord.NewEmbedBuilder().
        SetTitle("Bot Status").
        SetDescription("Everything is running smoothly!").
        SetColor(0x00FF00).
        AddField("Uptime", "24 hours", true).
        AddField("Ping", "50ms", true).
        SetFooter("Bot v1.0.0", "").
        SetTimestamp(time.Now()).
        Build()

    // Create a thumbnail
    thumbnail := []byte("...image data...")

    // Send message with embed, file, and components
    event.CreateMessage(discord.NewMessageCreate().
        WithContent("Here's the bot status:").
        WithEmbeds(embed).
        AddFile("thumbnail.png", "", bytes.NewReader(thumbnail)).
        AddActionRow(
            discord.NewLinkButton("Documentation", "https://docs.example.com"),
            discord.NewPrimaryButton("Refresh", "refresh_status"),
        ),
    )
}

Builder methods reference

Here are all available builder methods:
  • WithContent(string) - Set message content
  • WithContentf(string, ...any) - Set formatted content
  • WithTTS(bool) - Enable/disable text-to-speech
  • WithEmbeds(...Embed) - Add embeds
  • AddEmbeds(...Embed) - Append embeds
  • WithComponents(...LayoutComponent) - Set components
  • AddComponents(...LayoutComponent) - Append components
  • AddActionRow(...InteractiveComponent) - Add button/select row
  • WithFiles(...*File) - Set files
  • AddFiles(...*File) - Append files
  • AddFile(name, description, reader) - Add a single file
  • WithAllowedMentions(*AllowedMentions) - Set allowed mentions
  • WithMessageReference(*MessageReference) - Reply to a message
  • WithMessageReferenceByID(snowflake.ID) - Reply by message ID
  • WithFlags(...MessageFlags) - Set message flags
  • WithEphemeral(bool) - Make message ephemeral
  • WithSuppressEmbeds(bool) - Suppress auto embeds
  • WithSuppressNotifications(bool) - Suppress notifications

Best practices

  • Keep content concise: Discord has a 2000 character limit for message content
  • Use embeds for structure: Embeds are great for organized, formatted content
  • Limit embeds: Maximum 10 embeds per message, 6000 characters total
  • Optimize images: Keep file sizes reasonable for faster loading
  • Handle mentions carefully: Always use AllowedMentions to prevent abuse
  • Use ephemeral for errors: Error messages should usually be ephemeral
  • Add descriptions to files: Help screen readers and improve accessibility
  • Validate URLs: Ensure embed URLs and images are valid and accessible

Next steps

Build docs developers (and LLMs) love