Introduction to Python Coding With Discord Bots

Introduction to Python Coding With Discord Bots Featured Image

My sudden interest in Discord bots has inspired me to create a series focused on learning Python by building Discord bots. If that sounds interesting to you, keep reading!

Table of Contents

Why Learn Python Through Discord Bots?

As someone who went down the traditional education pipeline, I find that learning to code can be somewhat of a slog. After all, the traditional way to teach programming is to give a semester for each of the following subject areas:

  • Syntax & Semantics
  • Data Structures
  • Algorithms
  • Compilers
  • Computer Architecture

This setup works fine for folks who are dedicated to getting their degree, but it’s not all that interesting. After all, the topics above are fairly abstract in nature, and the coursework often revolves around that. For example, a lot of time is spent learning Big O notation and how to analyze runtime of some code.

Unfortunately, it’s often not until way later in these programs that folks get a chance to actually apply what they’ve learned. For example, I took a game design course my senior year. That’s when I learned real world skills like version control and code reviews.

At this point, you’re probably wondering how education got to be this way. After all, it wasn’t always like this. Universities used to be practice-based, but that all changed after World War II. These days the focus seems to be significantly more on the academic pipeline, so theory takes precedence. Ideally, a balance between the two is preferred.

Interestingly, while I spend a lot of time critiquing higher education, I also like to do a bit of learning myself. And as it turns out, learning is a lot more fun when you do something you enjoy. For example, I’ve been studying Japanese, and I’ve found it to be a lot more fun than learning Spanish because I can apply it in contexts I already enjoy: anime and manga.

Taken together, I wanted to try my hand at making some introductory coding curriculum that was more interesting and application based. In other words, rather than learning syntax through all the classic algorithms, we could try writing up code that actually does something.

Fortunately, I learned how to code Discord bots recently which turned out to be fairly approachable for me despite my lack of experience in that domain. I thought that they were so approachable that I could even try developing some curriculum around them for beginners. This is my attempt at that!

Overcoming the Initial Learning Curve

One of the challenges of putting together a series like this is getting over the learning curve that comes with working in a particular domain. For example, here’s what a Hello World program looks like in Python:

print("Hello, World!")

And, here’s what a Hello World program would look like for a Discord bot:

import discord
webhook = discord.Webhook.from_url("<your webhook url>", adapter=discord.RequestsWebhookAdapter())
webhook.send("Hello, World!")

If you’ve never written a line of code in your life, that first example is a lot easier to manage. This second example, unfortunately, is a bit more complicated. As a result, the traditional education system might make us back up and learn “the fundamentals.”

Of course, if you’ve ever taken one of these fundamentals courses, then you’ve almost certainly seen a piece of code that looks like this:

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, World!");
  }
}

And, they get away with sharing examples like this by treating everything except line 3 as boilerplate.

That said, there’s still a lot to process here. Even if we exclude everything except line 3, we still have to make sense of System, out, and println(). Alternatively, we can do what most courses do and just ask students to memorize those keywords for printing without ever explaining what they actually do.

In this series, I’ll be explaining what every line of code does in layman’s terms. After all, I don’t think it’s mission critical to understand how everything works down to the flow of electrons. Instead, learn the gist and make mistakes. That’ll teach you much more than a blog post can.

Preparing for This Series

As an educator, I’m obsessed with new and different ways to teach programming content. When I first started this site in late 2016, I immediately started making a beginner programming series in Java. I’ve rewritten that series a handful of times over the years, and I felt like I could never get it right.

Then, I started writing a Python series where I went to incredible detail about Python before we ever even looked at a line of code. I really enjoyed writing that series—though it’s incomplete at this time—but it still felt lacking. That said, I recommend checking it out if you want to browse more traditional learning material. Also, I’ll likely be referencing it throughout this series, if you want a more thorough explanation of the various concepts.

That said, for this series, I recommend checking out the article that inspired this series: Write-Only Discord Bots Are Surprisingly Easy to Code in Python. It’ll give you all the steps you need to replicate the Hello World example from above. Then, in the next article, we’ll take a look at breaking down exactly what’s going on!

With that said, let’s call it quits for today. In the meantime, feel free to check out the next article in the series (if it exists) or browse one of the following related Python articles:

Likewise, you can check out some of these resources from the folks at Amazon (#ad):

Otherwise, take care!

Learn Python by Building Discord Bots (4 Articles)—Series Navigation

In 2021, I started toying with the idea of building discord bots. Very quickly, I got over my fear of learning something new when I realized I had nothing to be scared of. This feeling got me thinking: what if I created some teaching material around Discord bots? You could learn Python and build something cool at the same time! So, I decided to give it a go.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Code Posts