ShareBot

I have created a Discord bot that is currently in over 200 servers and counting!

The idea came to me when I was in a Discord voice channel with a friend, and we wanted to watch a video together. The typical way of achieving this would be to use an existing website such as mycircle.tv, and then share the link it creates with each other.

I thought it would be interesting to attempt to integrate this concept more with Discord. While I originally wanted to make it so the bot would join the voice channel and stream the video, similar to how a person would, it turns out Discord’s TOS don’t allow this.

So I was forced to split the bot into two parts; The discord part and the website part. The idea is that the discord bot allows you to search for the video you want, and it will then generate a link that everyone can click on that will take them into the same online room and give them synced video playback.

After doing some research I found the best tool to use was Socket.IO, as this would allow me to create different rooms and then sync the client’s player state with the server. I started off by following a basic Socket.IO tutorial on how to set up a chatroom, and then I modified it by bringing in the YouTube iFrame API and attempting to send the player’s current time to the server, and then have the server echo it back to the clients in the room. After a bit of trial and error, I got this working, and I also synced things such as if a video is paused or playing.

My next problem was making it so the bot could generate a link that the website could understand. I chose to format the URL so it contained two main things, the VideoID and the roomID. The video ID is the YouTube video ID that we want to load, and the roomID is a randomly generated value. The website then de-constructs the URL to separate out these two values, and then loads the video and joins the client into the requested room.

With this all working, I now had to make the Discord bot actually generate these links. The first method I tried was to make the bot simply separate out the videoID from a standard YouTube URL, but YouTube URLs often have their own extra information tagged onto them so this approach was not very effective.

I chose to implement the YouTube API into the Discord bot. When someone requests a video to watch, the bot queries YouTube, and then gets sent back an array of the videos it finds. I originally had it just return the first one, but now it gives you the first 5 it finds and then allows you to select the one you want before generating the link.

The Discord bot itself is written using Discord.net, while the website portion uses Javascript. I host the website using DigitalOcean, while the bot runs on my personal server.

The success of my bot came as a bit of a surprise, and when my bot reached 100 servers I had to verify it with Discord. This required me to fill out a very long form where most of it didn’t apply to what my bot did, but nevertheless Discord approved Sharebot and my creation has been added to many more servers since.

A simple tutorial showing how the bot works

I have recently integrated the YouTube API with the website, allowing it to find videos without the bot being required to generate the links, and while the implementation is currently quite primitive it does work well.

The original website was just thrown together in a notepad file, but a few months ago I completely re-made it and made a nicer looking site in Adobe Dreamweaver.

The main homepage
The room page

If you want to add the bot to your server, visit sharebot.xyz or check it out on Top.GG.