Discord server has a system to send messages automatically to a channel.
This system uses webhook, so you just have to send a web request to a URL and a message will be written on the selected channel.
This could be used in many ways, for example:
- Make a badge reader using RFID to send a message when someone is at your fablab.
- Display the temperature of a room each hour.
First we need to create a webhook in our server:
Click on your discord servername → Discord Settings Then click on Webhook → Create WebHook
Copy the Webhook URL
I used Arduino Create to write my code, but you can also use the classic IDE.
Here is a link to the code: https://create.arduino.cc/editor/madnerd/429197a3-8a40-4d2c-bc16-1a502cb26cd9/preview
Settings are inside arduino_secrets.h or the Secrettab
- SECRET_SSID: your Wi-Fi network name
- SECRET_PASS: your Wi-Fi password
- SECRET_WEBHOOK: your Webhook URL without https://discordapp.com
- SECRET_TTS: true to enable text to speech or false to disable it
Upload your code on your Arduino MKR 1010, you should see this message:
You can find more information on how to use Discord webhook here: https://discordapp.com/developers/docs/resources/webhook#execute-webhook
Here is also some information for text-to-speech: https://support.discordapp.com/hc/en-us/articles/212517297-Text-to-Speech-101
To send a message on discord, just type:
I used two libraries for this code:
- WiFiNINA: Wi-Fi manager
- ArduinoHttpClient: Web request