Skip to main content

Send Messages from ESP32 to Discord Channel with Webhooks

Send messages from esp32 micro-controller to your Discord channel, using Discord Webhooks. Send simple messages or formatted messages using Discord Embeds.

Discord has evolved far beyond its gaming roots and simple chatting. Emerging as a dynamic platform for communities of all kinds to connect, collaborate, and communicate in real-time together with bots, makes it an invaluable tool for fostering engagement and building communities around shared interests.

Now, imagine if your ESP32, with its capabilities to interact with the physical world, could seamlessly communicate with Discord. This opens up a world of possibilities. Suddenly, you can receive notifications, and updates, or even control your ESP32-powered devices directly from Discord.

In this post, we'll explore how to make this a reality, walking through the process of setting up your ESP32 to send messages to Discord servers.

Setting up Discord Bot #

Following the instructions in Discord's support page "Intro to Webhooks", create a new Webhook in your Discord Chanel.

Next to the channel name, click the settings cog

Select "Integrations", and click on "Webhooks" and "New Hook". A new Hook should appear below.

Click on it and copy the URL by clicking the "Copy Webhook URL" button.

Keep this URL by hand, as you will need it in a moment.

Preparing the ESP32 #

You can find a full code example in the GitHub Repository.

Create a folder named discord_message. This will be the main Arduino project's directory.

Secrets #

Create secrets.h file in the root project directory. Copy the following code:

#define DISCORD_TTS "false"
  1. Fill in your WiFi Credentials in WIFI_SSID and WIFI_PASS
  2. Paste the Discord Webhook URL you copied earlier. It should be in this format:
  3. If you want to enable Discord's text-to-speech for the messages, everyone who has tts enabled will hear it.

Discord App SSL/TLS Certificate #

Create discordCert.h file in the root project directory and copy the following code:

* Get current certificate:
* openssl s_client -showcerts -connect

const char* DISCORD_CERT = R"(

Please note this is certificate at the time of writing this post. If the certificate is changed in the meantime, you can get a new certificate with this command:

openssl s_client -showcerts -connect

ESP32 Code to Send a Message to Discord #

Create discord.h file in the root directory of your project. Copy the following code:

#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include "discordCert.h"

const char ssid[] = WIFI_SSID;
const char pass[] = WIFI_PASS;
const String discord_webhook = DISCORD_WEBHOOK;
const String discord_tts = DISCORD_TTS;

WiFiMulti WiFiMulti;

void connectWIFI() {
WiFiMulti.addAP(ssid, pass);
while (( != WL_CONNECTED)) {
Serial.println("WiFi Connected");

void sendDiscord(String content, String embedJson) {
WiFiClientSecure *client = new WiFiClientSecure;
if (client) {
client -> setCACert(DISCORD_CERT);
HTTPClient https;
if (https.begin(*client, discord_webhook)) {
https.addHeader("Content-Type", "application/json");

String jsonPayload = "{\"content\":\"" + content + "\",\"tts\":" + discord_tts + ",\"embeds\": [" + embedJson + "]}";
int httpCode = https.POST(jsonPayload);

if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = https.getString();
Serial.print("HTTP Response: ");
} else {
Serial.print("HTTP Post failed: ");


delete client;

void sendDiscordMessage(String content) {
sendDiscord(content, "");

void sendDiscordEmbeds(String embeds) {
sendDiscord("", embeds);

This code provides 3 functions:

  • sendDiscordMessage(String content): Send a simple message to Discord
  • sendDiscordEmbeds(String embeds): Send a message with Embeds to Discord
  • sendDiscord(String content, String embedJson): Send a simple text and embeds in one message

The main sendDiscord() function sets a Discord app certificate to WiFiClientSecure, sets the Discord message content and finally sends the message to the Discord Webhook.

Send the Messsage from ESP32 to your Discord Channel #

Create discord_message.ino file in the root directory of your project. Add the following code:

#include "secrets.h"
#include "discord.h"

String message = "";
String embedJson = "";

void setup() {
// sendDiscordMessage(message);
// sendDiscordEmbeds(embedJson);
// sendDiscord(message, embedJson);

void loop() {

As you can see, this is the main Arduino project's file. It simply begins the Serial connection and connects the ESP32 board to a WiFi network. If you uncomment any of the commented lines, it will send a message to Discord on ESP32 setup - after it boots and connects to the WiFi network. To resend the message again with this example, you can either reboot the ESP32 or move the sendDiscord...() function to loop() or the appropriate part of your application's code.

Simple Discord Message from ESP32 #

To send a simple message to Discord Channel, uncomment the sendDiscordMessage(message); line and set the message variable to any message you want to send to Discord.

- // sendDiscordMessage(message);
+ sendDiscordMessage(message);

For example, if we set the message as follows:

String message = "Hello from ESP32!";

And upload the code, after the ESP32 boots and successfully connects to the WiFi network, it will send a message to the Discord Webhook. After a few seconds, you should see the message in Discord:

Discord Embeds with ESP32 #

Discord embeds are a way to enhance the appearance and interactivity of messages sent in Discord. They allow users to include rich media, such as images, videos, and formatted text, in their messages. Embeds can be used to display information in a visually appealing format.

embedJson is an array of embeds and can contain up to 10 embeds in one message.

For example, if we set the embedJson as follows:

String embedJson = R"({
"author": {
"name": "Temperature Sensor",
"icon_url": ""
"title": ":thermometer: Temperature too high! **28.32°C**",
"color": 16711680,
"footer": {
"text": "",
"icon_url": ""

Uncomment the line sendDiscordEmbeds(embedJson); and upload the code.

- // sendDiscordEmbeds(embedJson);
+ sendDiscordEmbeds(embedJson);

The same as previously after the ESP32 boots and connects to the WiFi network, ESP32 will send a message to Discord, but this time with Embeds. With the above configuration, it would look like this:

Combine Discord Message and Discord Embeds #

If you want to send both simple text and Discord Embeds in one message, fill in both message and embedJson variables and uncomment the following line: sendDiscord(message, embedJson);.

- // sendDiscord(message, embedJson);
+ sendDiscord(message, embedJson);

This will send a message that would look like this:

Other ESP32 Discord Message Examples #

Spotify #

String embedJson = R"({
"title": "New song added!",
"color": 2021216,
"thumbnail": {
"url": ""
"fields": [
"name": "Track",
"value": "Scars To Your Beautiful",
"inline": true
"name": "Artist",
"value": "Alessia Cara",
"inline": true
"name": "Album",
"value": "Know-It-All",
"inline": true
"footer": {
"text": "Added Februrary 5, 2018 at 11:48AM",
"icon_url": ""

This example could be used for an application that integrates ESP32 and Spotify and sends the updates to Discord.

Other Embeds Features #

String embedJson = R"({
"author": {
"name": "Birdie♫",
"url": "",
"icon_url": ""
"title": "Title lorem ipsum something very nice",
"url": "",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink]( `code`",
"color": 15258703,
"fields": [
"name": "Text",
"value": "More text",
"inline": true
"name": "Even more text",
"value": "Yup",
"inline": true
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
"name": "Thanks!",
"value": "You're welcome :wink:"
"thumbnail": {
"url": ""
"image": {
"url": ""
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": ""

This example demonstrates most of the features of Discord Embeds. You can find more details about Discord Embeds here.

Additional Resources #

Conclusion #

In this post we have created an example program for ESP32 that sends a message to Discord channel, using Discord Webhooks. We have tested different scenarios, such as sending a simple text and sending Discord Embeds, which allow better message formatting. This example can be used as an example for a more complex application, which would send a message to Discord when sensors connected to ESP32 detect anomalies or similar scenarios.