Skip to content

hdadhich01/discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PyPI - Status PyPI

Discord Bot Tutorial

This is a tutorial on how to make a Discord Bot with the discord.py library along with a 24/7 uptime. This project should take anywhere from 15 to 45 minutes.

Platforms

Make sure you sign up for the following platforms before proceeding. Since this project will be completely in the cloud, there are no installations necessary for this project.

Getting Started (Discord)

This is the platform where your bot will operate

Creating a Server

This is where you will create the platform for your bot to function on

  • Go here
  • Read this short article and create your server
  • Name the server Replit Bot Testing

Creating the Application

This is where you will create an application for your bot

Creating the Bot

This where you make the bot for your application

  • Go to the 🧩 Bot section
  • Click Add Bot
  • Click Copy under Click to Reveal Token
  • Paste and store this token in a text file on your device (will be used later)

Inviting the Bot

You will need to invite the bot to a Server in order to make it function

  • Go to the 🏠 General Information section
  • Click Copy under Application ID
  • Go here and paste the Application ID
  • Select your previously made server and click Authorize
  • Once done, go back to Discord to check for confirmation

Getting Started (Replit)

This is the platform where you will host and run the code for the bot

Creating a Repl

  • Go here
  • Make a new repl
  • Select Python as the language
  • Name it "Discord Application" or anything else you want

Adding files

  • Add a keepAlive.py file as shown below

  • Create an environment variable as shown below and use your previously saved token for the value
  • If you do not have your token, go back here and retrieve it

Booting Up

You will now implement the necessary tools to boot up the bot

main.py

This code will be the framework of your bot. It contains a few commands and events to demonstrate the layout of the discord.py library usage. You can add more commands/events later as you read through the documentation. For now, paste this code into your repl's main.py file.

keepAlive.py

This code that will allow your application to run 24/7. Paste it into your repl's keepAlive.py file

from flask import Flask
from threading import Thread
import random

app = Flask("")
@app.route("/")

def home():
  return("Online!")

def run():
  app.run(host = "0.0.0.0", port = random.randint(2000, 9000))

def keepAlive():
  thread = Thread(target = run)
  thread.start()

Uptime Robot

The last step of this tutorial is to set up the UptimeRobot monitor

  • Click ▢️ Run on the top of your repl
  • Copy the URL in the top right of your screen (mine was https://Replit-Bot.hdadhich01.repl.co)
  • Go to your UptimeRobot dashboard and add a new monitor
  • Fill out the fields as shown below, and use your own repl's URl for the empty field

Click Create Monitor, and that's it. You have completed building your Discord Bot!

Testing it Out

Go to your previously created server and test out the following commands.

  • !help - displays a list of all commands
  • !hello - says hello back
  • !ping - displays the application latency
  • !predict <question> - predicts the outcome of your question
  • !color <hexCode> - displays the given color code in an embed
  • !dm <user> <message> - sends a direct message to the specified user

Support

If you encountered any issues, feel free to direct message me on my Discord found here!

About

πŸ“œ Learn how to make and host a simple Discord bot

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages