Learn about APIs and Make a Discord Bot!
- Make a Discord Bot
- 1-on-1 Check-ins with Students
Application Program Interface
An API gives a list of commands that programmers can use to access functionality that they themselves haven’t coded or even necessarily know how they work but can still access and get the data they need.
APIs control access to resources such as data.
They are used to communicate between disparate services.
- An interface for different pieces of software to communicate together over networks
- These are created by organizations, programmers, and companies to access their data
- There are open APIs and those requiring authorization.
- start out by using APIs that have tutorials or sample code and consider trying out ones that don’t require authorization as you learn how to use them!
What Are APIs? video
- YouTube API - Allows you to display videos on a web site.
- Twitter API - Allows you to display Tweets on a web site.
- Facebook API - Allows you to display Facebook info on a web site.
A link of Open APIs not requiring authorization
Web API Intro on w3schools
Build a Discord bot
Glitch Discord Botkit
- Log into Glitch. Remix the Glitch app - Glitch Discord Bot starter Then Preview your Project and go to it’s WEBSITE.glitch.me/install page
- Go to the Discord developer center
- Create a New Application and give it a name. I chose the same name as my Glitch project.
- Go to Bot on the sidebar and Add A Bot.
- If you put private info in
server.js then anyone on Glitch.com can see it! That’s bad. So go back to your project on Glitch and open your private
.env file. This file is a hidden file, sometimes called a dot file because the name starts with a dot. Paste in your Discord token as a variable, like this:
DISCORD_TOKEN=A1b2C3d4E5F6EtcEtcEtc. If your token is compromised because you get hacked, accidentally reveal your token onscreen in a video, etc, you can always regenerate a new one on your Discord developer console. By the way, this
.env file is a Bash commandline script.
- Glitch is a freemium model. If you pay, your server is supposed to run 24/7. If you are using their server space for free, they use a system to keep your project turned off until someone tries to access it, at which point they turn it on. That’s why there is a loading screen. But we want our bot to run continually. We don’t want our Bot to go to sleep. So we can create an UptimeRobot account to keep it awake. Ok, so go to UptimeRobot, make an account, and verify yourself via email.
- Once logged into UptimeRobot, go to My Settings and under API Settings click to create a Main API key.
- Copy your UptimeRobot Main API key and go back to your Glitch project’s
.env file. Save your API key in a variable there, like
- Now you have to select a Discord server to deploy your bot to. Open your Glitch App’s index page (Preview it) and click the Bot Authorization URL. Please choose our class Scripting For The Web! If you don’t see this option, you may have done something wrong! Go back and go through the steps in order.
- Now test your bot! Go back to your Discord server. Write
@myBotsName !thanks @someone-elses-name.
- Now you can make new bot skills. We are using a framework (starter code library and templates) that call different functionality skills. Go to
skills > hears.js to see how these are made.
- Check out more example Discord bots here on Glitch. Check out the grittybot, bizbot-discord, and discord-magic-8-ball.
Finish building a custom bot for our class Discord. Add a bot that adds joy to our class Discord!
Please leave my announcements and video-recordings channels alone!