The Hacker News - Discord Bot

Project’s GitHub Repo

profile

It was Spring 2022, I was working on concluding my senior year of my undergraduate. Also during this time, me and a friend worked on a project we called “The Hacker News - Discord Bot”.

During college, and even now, me and almost all my friends use Discord as one of our main social messaging platform. At the time, and even now, I want to be up to date about cybersecurity news. So I thought, as a fun project, me and my friend would make a Discord bot that would re-post cybersecurity news from The Hacker News into a Discord server. I presented the idea to my friend and he loved the idea, so we started developing it.

The Hacker News (THN) is a cybersecurity news site. Now, THN is NOT Hacker News. There has been some controversy about how “The Hacker News” name is very similar to “Hacker News” which is a very popular, and legendry, social news website that focuses on tech entrepreneurship. But, as some one that uses The Hacker News all the time, I believe The Hacker News is a good source for getting cybersecurity news.

Well working on this project, one challenge I ran into was finding a way to extract the news from THN. The only options available was to either use the Twitter API or to web scrape THN. I spent sometime trying to get the Twitter API to work but gave up because Twitter made it really difficult to setup and use their API. So I resulted to web scrape THN instead. Sense the codebase was going to be written in Python, I used the requests and beautifulsoup4 to do the web scrapping.

With the scraper working, the next thing we tackled was the Discord bot. Making and deploying a Discord bot is very simple. So we quickly got the bot working in less then a day. We also got the Discord server setup during that time frame as well.

One feature we added as a “filters” feature. This feature would sort THN articles by rather it was “apple-news”, “google-news”, “linux-news” and/or “microsoft-news”. It would sort those types of news into their own channels. There was still an “all” channel that would contain all the articles but we thought this feature was nice because it sorted the types some what and was not that challenging to make.

Knowing all of this, this is a general idea of how the Discord bot worked:

  1. Every 1 hour, it would scrape THN and extract key information about an article. This information included: title, details, date, and article’s url.
  2. The bot would then check it’s message history in the server to see which articles it has scrapped is new. This makes sure the bot does not re-post articles it already posted.
  3. It will filter the new articles by certain topics, as explained above.
  4. With all the articles collected and filtered, the bot would then post the url of each article into it’s Discord server as well as the post’s respected channels.
  5. After all of this, the bot waits for another hour to continue the same steps again.

All in all, the discord bot was written entirely in Python and used the following 3rd party packages: beautifulsoup4, requests, discord.py, and python-dotenv. Also, the Discord bot was hosted on my Raspberry Pi 3 B+ that was running the 32 bit Raspberry Pi OS Lite. We would run the bot like this:

python3 bot.py &

Where the “&” allows the process the run in the background.

After we got the bot and server all setup, we shared our project will all of our friends and classmates. In a week we got around 25 people to join the server.

But after a few months, we noticed that people did not really use the server and most of them had either left the server or muted all the channels in the server. The main reason why they did this was because most of the users wanted more personal and custom filter options and most of them did not care about cybersecurity that much.

Because of this, we decided to shot down the Discord server. This project ran from February 2022 to May 2022, officially closing shop on May 25, 2022. On this day, we stopped the bot, deleted the Discord server, deleted the Discord bot account we created for this project, and made the code completely open source. You can check out the code here: https://github.com/MehmetMHY/thn-discord-bot

All in all. This was a fun project and we learned a lot. Also, at the time we did not know this, but this project was the initial start/version for our biggest project yet: Notify-Cyber.