How to Make a Discord Bot Tutorial Python No Coding Experience Needed

by Mechanical Max in Circuits > Software

1230 Views, 9 Favorites, 0 Comments

How to Make a Discord Bot Tutorial Python No Coding Experience Needed

How to make a Discord Bot Tutorial Python No Coding Experience Needed
Example bot output.png

This article covers all of the steps listed in my YouTube video about creating your first discord bot. I set a goal that I would create a working discord bot back in December, so I began researching how to make the code work and I couldn't find everything I was looking for in one place. That's why I decided to write this article and create a YouTube video about the bot to reveal how to set up a basic bot.

After I got the bot working, I challenged myself to get the bot to display my subscriber count.

The full bot is completely automated, and all you have to do to get an updated subscriber count is send the "!subs" command.

My goal in this tutorial is to show you how to set up your own custom bot all in one place, then show you how I used YouTube's API to get subscriber data.

Adding a New Bot to a Server

DeveloperDiscord.png
generalinfo.png
BotPage.png
OAuth2.png

In my YouTube video, I added a second "Application" to walk you through from scratch what I did. If you want to see the video tutorial instead, it is embedded above.

First, go to https://discord.com/developers/ and log in. Next, go to "New Application" and enter the name of your project. This will open a lot of information that you do not need for your first bot, so follow along with the images above to see where to click.

In the general information tab, change the name and picture of your project. Next, go to the bot tab and create a bot. Here you can change the image and name of your bot. This is where your "Token" is stored (think of it as a password to use your bot). Don't share this with anyone; a bot is very powerful, so only give it to people you trust. If your token does get lost, hit "Regenerate" to get a new one.

Now we can go to OAuth2 and check that you are making a bot and give it administrative permission. For more specific bots, you may want to uncheck some of the permissions, but it is ok to allow all for this project. Copy the link generated and paste it into a new tab. From there, add it to a server that you made for testing, and you should see your bot appear!

Writing the Code

Replit.png
replit main.png
.env.png

Now we can start telling the bot what we want to do. I already wrote the code for this part, so just copy what I have Here to test if everything is working.

First, make a Replit account and create a new project. We will write in Python, so make sure you select python when setting up. Next, copy all of the files I have and make sure the names of the files are the same.

Before the code runs, it's vital that you create a new file called ".env" so you can protect your token. Replit makes all free accounts public, so if you just put your token in the code, people could steal it. The .env folder is private and all you have to do is type "TOKEN = " then copy your token from your discord bot application from the last step.

Now hit run, and your screen should look like the picture above. If it doesn't, look for spelling errors. Stay persistent, the solution is just around the corner. Try watching the above video too, or asking in the comments section for help.

Keeping the Bot Active for Free

UpTimeRobot.png
UpTimeURL.png
UpTimeRobot.png

Now you have the bot up and running. Great! The only problem is when you close the tab the bot no longer works. We have a solution: UptimeRobot (https://uptimerobot.com/). This will automatically "ping" your code with the link generated in the second output window.

Go to UptimeRobot and make an account. Next, hit add monitor and enter the information in the above picture. Copy the URL generated in the second output window from repl.it into UptimeRobot.

Now you have a working discord bot! Congratulations! Now you can continue on your bot-making journey with all of the setup complete.

In the next step, I will show you how I automated my bot to output subscriber data from my YouTube channel.

Connecting to YouTube's API

YTAPI.png
NewProjectAPI.png
enableAIP.png
YTData.png
Create Credentials.png
YTLink.png
ENVPT2.png

This step is a lot more complicated, but the good news is all of the code is already written Here. All you have to do now is follow the above pictures to connect the bot to a channel of your choice.

First, go to https://console.cloud.google.com/ and use the navigation menu at the top left to get to "APIs & Services." Create a new project, and give it a name. Next, click on ENABLE APIS AND SERVICES at the top, search YouTube, and select the data API.

Now select create credentials and an API key will appear. You will also need the YouTube Channel ID for the bot to know which channel you want to get the data from. Finally, as in the second step, create a .env file and enter in your key and ID as shown in the last picture. Make sure everything is spelled correctly, and it should work!

If you have any issues, try using my channel ID to make sure the code works, then use yours. If you can't find the ID in the URL, try going to the creator studio on YouTube. As always, if you want to learn more check out the YouTube video above and ask your question in the comments.

Congratulations! You now have a working discord bot that connects to an API!

Future Directions

Now that you have your first bot up and running, it's time to continue on your own. There are plenty of more specific tutorials online, and now you can understand some of the technical terms. Discord bots are no longer a foreign subject!

Try setting a goal for yourself, and keep working towards it. There were plenty of times when I started making this project that I had no idea how to approach the problem. I stuck with it, researched more about bots, completed tutorials, and asked friends for help.

Overall, persistence is key. It's an important skill to set goals for yourself and work towards them no matter how difficult they seem.

Now go make some improvements, and tell us about your results in the comments!