Skip to content

Your first V2 message

In this guide you’ll send a message like this one. Pick your language in the tabs: your choice is remembered on every page.

Preview
My BotAPPToday at 12:00 PM

My first V2 message 🎉

Made with a Container and a Text Display.


payload.json
{
"flags": 32768,
"components": [
{
"type": 17,
"accent_color": 5793266,
"components": [
{
"type": 10,
"content": "## My first V2 message 🎉\nMade with a **Container** and a **Text Display**."
},
{
"type": 14
},
{
"type": 1,
"components": [
{
"type": 2,
"style": 1,
"label": "Hello",
"custom_id": "say_hello"
}
]
}
]
}
]
}
  1. Create an application in the Discord Developer Portal and copy the bot token (Bot tab).

  2. Invite the bot to your server with the Send Messages permission.

  3. Install the library for your language:

    Nothing needed: just curl or any HTTP client.

Save the JSON above as payload.json and send it:

Ventana de terminal
curl -X POST "https://discord.com/api/v10/channels/CHANNEL_ID/messages" \
-H "Authorization: Bot $DISCORD_TOKEN" \
-H "Content-Type: application/json" \
-d @payload.json

An interaction response uses the same body, wrapped in type and data:

POST /interactions/{interaction.id}/{interaction.token}/callback
{
"type": 4,
"data": {
"flags": 32768,
"components": [
{ "type": 10, "content": "Command received!" }
]
}
}

See Interactions for the details.

Webhooks ignore components unless you add ?with_components=true:

Ventana de terminal
curl -X POST "https://discord.com/api/v10/webhooks/ID/TOKEN?with_components=true" \
-H "Content-Type: application/json" \
-d @payload.json

To display an image or file uploaded by your bot, send the request as multipart/form-data and refer to the file with attachment://name:

Ventana de terminal
curl -X POST "https://discord.com/api/v10/channels/CHANNEL_ID/messages" \
-H "Authorization: Bot $DISCORD_TOKEN" \
-F 'payload_json={"flags":32768,"components":[{"type":12,"items":[{"media":{"url":"attachment://photo.png"}}]}]}' \
-F "files[0][email protected]"

Your bot can now send V2 messages. Next, learn how to respond when someone clicks a button.