How hard would it be to learn to code a Discord bot?
I've got a notion to put some of my extra energy into learning to code. I'm familiar with EXTREME basics - I did some coding in BASIC and Python when I was younger ("Hello world" type stuff, and some futzing around with my Ti calculators programming capabilities) and while I had a pretty good knack for it I never developed it further.
I'd like to use this as a chance to create something useful for me - a discord bot for my server. We have a handful of bots doing a few odds and ends, and I'd like to try and work something out to consolidate things. That's getting a bit ahead of myself though - initial scope would be simple: have the bot do a simple task like counting +rep points, or something silly like telling a joke.
I don't really have any idea of where to start - what resources I need, what language to use, or really anything about how this all works. Any assistance at all would be welcome!
To be clear - I want to learn to code, and specifically I want to learn in a way where it is immediately applicable and useful in a context I care about.
This is a dead simple library for creating Discord bots: https://discord.js.org
You can focus on the functionality and let the library handle the boring protocol stuff.
If you aren’t against LLM, using something like Cursor, Gemini or DeepSeek as a coding assistant is a decent idea. Just don’t blindly use the stuff they generate, try to understand it too.
There is also discord.py if you're a snake-aligned programmer.
I used both,doing python first to wrap my head, then using js to learn node.
This is what I used for the few Discord bots I wrote for me and my friends. OP, if you're interested, this codebase is a few years old, but you can check out this code repository as an example.
For context, we were playing a lot of Rocket League as we were in college and some virus was going around at the time so we couldn't be around each other. We wanted a way to all check our "session" stats and I didn't feel like building out a front end, so I threw together a Discord bot. Fair warning, there's probably a lot of not-so-great patterns and practices here, but for getting something started, this may be useful.
One of the CS educational teams I was on made a Discord bot the final project for one of our introductory programming classes. I think it’s a great first project.
We had our students use discord.py. If you want to continue learning Python, you can use that library to do most everything you want.
The other commenters suggested Javascript; I don’t know enough about JS to know if it is a good first language, but learning multiple languages early is pretty much always a good thing (so you don’t attach the syntax to the logic too much in your head).
If you end up using Python, feel free to DM with questions!
I’ve built a couple discord bots using JavaScript and discord.js. I’d say it’s pretty straightforward to do for someone who already knows JavaScript but I can’t fairly say how easy it is from a newbie perspective.
Discord.js has a tutorial with some resources to learn JavaScript linked as all
https://discordjs.guide/#before-you-begin
But I think if you’re determined to learn you’ll be able to make some good progress, JavaScript in particular is one of the topics AI chatbots are best at and might be helpful to learn the stuff that most people assume everyone already knows.
This is the framework I'm most comfortable with, although they do things a bit weird and some things are a bit out of date.
Scaffolding this (installing everything you need to start writing code, copying the right files,etc) is the hardest part, so I might not recommend it for that reason, but if you want to learn Python instead of JS then I'd prob recommend beginning with this.
One of the classes the company I teach with offers a course on it. If they can get preteens to do it, I think you can do it too.
I was recently successful in programming an IRC bot in Python by just 'vibe coding' it with ChatGPT (o3-mini-high). Worked great. I know you are saying you want to learn to code, but maybe messing around with an AI is a good way to start? You can have it break down the code it writes and explain it all to you so you can start to understand what it is doing and how code works.
My bot has the following functionality, each feature accomplished with a single GPT prompt that spit out working code first try:
Monitors a GMAIL account for email that comes in with an image attachment which is then downloaded and uploaded to Imgur and the link posted to the IRC channel. It also converts any image format not supported by Imgur to JPG before uploading.
Uses an API call to generate Dalle-3 images with a !dalle <prompt> command, which it then generates and uploads to Imgur and posts a link to the channel.
Scrapes information (Title, Duration, Length) for any Youtube link posted to the channel.
Leave a message for an offline user that then gets relayed to the user when that user logs on next, it chose to use SQLite to do this all on its own.
I've never typed a line of code in my life and I was able to create this in a single weekend, if it did produce an error I just pasted the error into GPT and it fixed the issue and spit me out the working code. It explained step by step for me how to setup the accounts and API's as needed.
So while this is really 'cheating' when it comes to coding I was able to produce something that works right away with zero coding knowledge, I don't know why you couldn't do something like this to get working results quickly while having the AI explain everything to you as it goes so you can learn what is happening. I'm really excited about what I've been able to accomplish, it has me thinking of what other nifty useful simple tools I can create for myself, we are entering a new world of coding for the average joe.
Discord bots are a very common place for people to start learning to code in my experience. If you use a library like discord.py or discord.js like people suggested, it basically turns into regular coding, but with different input/output functions. So whereas with regular Python you'd do
print("Hello world")
, with Discord code you'd just use something likebot.send("Hello world")
. It doesn't really require you to learn much Discord-specific stuff - just general programming.