Happy birthday to Sleepy Discord

written on Nov 27, 2018 by Hao Qi Wu

Sleepy Discord is now 2 years old. The first line of code for Sleepy Discord was first written on May 28, 2016. You may have noticed something, this article was written in November. So that means that this article is 6 months late. As they say, "it's better late than never." and this quote is true in this case.


I like to say it's because I wanted to make a Discord client running on hardware that wasn't a laptop or desktop, for example, video game consoles. But that's a lie. I'm sorry to the people I told that lie, the real reason was that I was posting a lot of NSFW pictures on Discord and I needed to keep track of all of them and noticed the lack of c++ libraries. Sadly I never got around to making that bot because I stopped posting NSFW images on Discord. However, I wanted to write that the bot in a language that I liked because, to be honest, I don't like js. In hindsight, I could have just learned a new language and used that to write the bot. However if I did that, then this library wouldn't exist.

The First lines of code

So let's look back and see what's the first lines of code for Sleepy Discord.

#include <cpr/cpr.h>

For those that don't know c++, #include includes other source files in a source file. This source file being inside the cpr directory and the file cpr.h. This is a file that is part of the cpr library, a wrapper over libCURL, a http library written in c. This is because the first thing that was done to make Sleepy Discord was to connect to Discord. To do that, we needed to get the URL to connect to Discord's WebSockets server and we can get that URL by making a request to Discord to give us the URL. To make a request we need some way to make an HTTP request in c++. So let's take a look at the code to do this.

auto a = cpr::Post(cpr::Url{ "https://discordapp.com/api/gateway" });

Basically a simple post request to https://discordapp.com/api/gateway that is stored into the variable a.


I ended up talking a lot about the possible futures for Sleepy Discord so make it a separate article. That will be released later, but if you want to look into my plans for Sleepy Discord, check out my to-do list.

Thanks for reading! 😄