Skip to content

Instantly share code, notes, and snippets.

@maditnerd
Last active November 10, 2022 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maditnerd/226dc2f5f43337457523d8be896a9dc2 to your computer and use it in GitHub Desktop.
Save maditnerd/226dc2f5f43337457523d8be896a9dc2 to your computer and use it in GitHub Desktop.
/*
Use a ESP32 as a Discord WebHook Serial "Modem"
If you use an 5v Microcontroller you will need to make a voltage divider using resistor (or a level shifter)
https://forum.arduino.cc/t/arduino-uno-serial-communication-with-esp32-using-voltage-divider/667516/14
*/
#include <Discord_WebHook.h>
Discord_Webhook discord; // Create a Discord_Webhook object
// How to get the Webhook URL
// https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
String DISCORD_WEBHOOK = "https://discord.com/api/webhooks/id/token";
void setup() {
Serial.begin(115200);
discord.begin(DISCORD_WEBHOOK); // Initialize the Discord_Webhook object
discord.addWiFi("ssid","password"); // Add WiFi credentials (you can add multiples WiFi SSID)
discord.connectWiFi(); // Connect to WiFi
}
void loop() {
// If a message is received on the Serial Port (TX/RX)
while (Serial.available() > 0) {
//Read it as a String until the newline
String command = Serial.readStringUntil('\n');
// Check if the message start with message:
if(command.indexOf("message:") == 0){
// Remove message: from the String
String message = command.substring(8);
Serial.println("[SERIAL] Message: " + message);
//Send the message
discord.send(message);
} else {
Serial.println("[SERIAL] Invalid command, for example use: message:Hello World");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment