This project is one of my favorite open sourced projects that I have made recently. One of the reasons why it is my favorite is that because in this project I’ve used my experience from web development combined with knowledge from the IoT world of electronics. Second reason why I’ve so enjoyed to work on this is because this library is intended for use by other developers like me who can transform their ideas into real projects. Library is written in pure C language and utilize modern programming mechanisms like WebSockets and HTTP requests, which made the realization of this project even more challenging and interesting.
For those who are not big fans of reading I have made YouTube video about this project. There I have explained how to use library and presented some basic demo application.
What is Discord?
For those who are not familiar with Discord, Discord is a VoIP, instant messaging and digital distribution platform designed for creating communities. Users communicate with voice calls, video calls, text messaging, media and files in private chats or as part of communities called “servers”. Servers are a collection of persistent chat rooms and voice chat channels. Discord runs on any platform like Windows, macOS, Android, iOS, iPadOS, Linux, as well as in web browsers. As of July 21, 2019, there are over 250 million users of this software.
Discord bots are something like AIs that can perform a number of useful automated tasks and Discord commands on your server, such as welcoming new members, moderating content, and banning rule breakers. You can use Discord bot commands to add music, memes, games, and other content to your server.
To be less abstract, bots are special user accounts on Discord which we can create for free, and then with using authentication token and some code, we can automate our bot to do some useful stuff like auto respond on some user messages, or check if some user spamming in channel and make desired actions like mute or kick that user from server, etc…
Discord bot on the IoT device
To be more specific, what if we adopt bot to the IoT device? Well, then with the messages from Discord channels we can control the state of home devices, or we can collect some sensor data from device environment and send it to the Discord channel, etc… Basically in that scenario, we can use Discord as totally free communication layer. Stuff becomes more powerful with the fact that Discord communicates with their clients through the permanent WebSocket channels, which provides bidirectional real-time and low-latency communication with bots, or IoT devices in this particular case.
Pretty interesting. Isn’t it?
Library itself is written in C and it is adapted to work with ESP-IDF framework. If you never heard about ESP-IDF, that is a framework for developing applications for ESP devices in C or C++ programming languages. It’s primarily written by Espressif (manufacturer of ESP devices), but later it is open sourced and adopted by huge community on the GitHub. Today, many popular platforms rely on ESP-IDF framework, like Arduino, PlatformIO and similar.
ESP-IDF has developed a lot in recent years and its architecture today allows us to easily write our own components (extensions). This library is just that – an extension (component) for ESP-IDF and I have named it as esp-discord.
Source code of this library is fully-opened and available under MIT license on GitHub on the next link:
Even if the library contains big number of implemented bot features, there is a lot of space for upgrading and adding new features. Some of the implemented features in library are: sending and receiving messages, getting roles or channels, checking user permissions, react to messages, downloading attachments and so on.
Pull requests on GitHub repository of this project is more than welcome so if you want to contribute to the code, go ahead, clone the repository and implement some new feature.
How to use library?
For the tutorial about how to use library and how to make the basic Discord bot please check the video that is embedded above, at Introduction.
Projects built with esp-discord
Here is some demo projects that I have built to present the power of this library and what we can accomplish if we have just an idea:
Discord-driven RFID attendance system
Over-The-Air firmware live updates
Discord voice status monitoring ESP32 bot
More examples of using esp-discord library, as well as this demonstrated projects, are open sourced and available in the next GitHub repository:
As we can see, library is already heavily loaded with features and has great potential for future upgrades and improvements. I’m happy that I have received nice feedbacks from the community and interest to use this library in their projects.