top of page
Search

Discord Bot (Python)

  • Writer: XiuJia Lim
    XiuJia Lim
  • Jul 10, 2020
  • 2 min read

Updated: Jul 10, 2020

Often during my free time, I would create/develop applications. For this project, I had decided to create a discord bot coded in Python as Python was the first programming language that I had learnt in my first year of Polytechnic.

I started my journey of building the bot by looking for libraries for Python that can aid me in creating applications that utilizes the Discord Application Programming Interface (API) as well as the documentations.

At that point, I had created the basic structure of the bot needed to turn on it as well as to create its own rich presence (RPC) which is, in this case "Watching your every move".

As I proceed to build my bot, I keep a log to keep track of what I did and the progress of my bot. Some troubles that I had met while building was the outdated Documentation. The reason was, the documentations that discord.py had was quite messy for me especially when it was my second time reading or finding a documentation. The latest documentation had only the changes that they had made to the codes, hence this meant that I had to look through past documentations and toggle between the old and newer documentations just to get the right codes down. As time past, I got used to its documentation and learnt how the contents of the documentations were organized and written.

The next problem was which object I should create my bot as, Client() or Bot(), I coded and tested both types and I concluded that I should build my bot with Client(). Reasons being, Client() is for developing or constructing your own commands, whereas Bot() has whatever Client() has and as well as built in commands.

After I added some straightforward commands, I decided to implement music functions into my bot. During my search, I tend to see music functions and general functions separated between the bots, meaning, music functions are in music bot and general functions and other utilities in another bot. I was unsure if the reason as to why they separated the codes was because it was harder to combine them together or they were simply just separating it because they want it that way. I decided to combine the 2 sets of functions together.

I would say building the "play" music function was one of the toughest for me, as I had to search for a suitable and working library for my bot to retrieve and download/stream the music in the music channels as well as creating a music player class.

After which, I needed to allow my bot to be able to play multiple songs that were queued.


After the music functions, I moved on to level functions and system. Things got tricky since I have yet learn about SQL or any database other than just a simple data text file or comma-separated value file (CSV) or shelve. Using either ones are not as effective as compared to a proper database like MySQL.


As this was built purely based on personal interests and curiosity, I decided not to host the bot such that it can run 24/7.

 
 
 

Comments


Post: Blog2 Post
bottom of page