DiscordBotTemplate
A Discord Bot template
Requirements:
- Python3
- pip
- Pycord
Not required but useful
- dotenv
Getting started
You will need to create a bot using the discord developer portal you will also need to pip install both pycord
I would recommend getting dotenv and saing your token in that file, however it is not necessary if you plan to keep the bot running on your local machine only and do not plan to upload it to github.
once you have created your bot you can under OAuth2 you can select the permissions your bot needs and get the link to invite the bot to a server. once done go to the Bot tab and copy your Token. You will place this in a .env file. eg: Token = ygawiushjfgblfkhkjbn this is to keep the token safe if you plan on uploading it to your own github repository. Otherwise you can place it directly inside the main.py file.
Now you can create any further commands you would like and enjoy your very own customisable discord bot.
Source Code: Main.py
import discord
import os
from random import randint
TOKEN = "" #place your bots token here
bot = discord.Bot() #defines the bot
#this event will print to the console when the bot is running and ready for commands
@bot.event
async def on_ready():
print(f'{bot.user} is ready')
#below are the commands, have fun with it, you are only limited by your imagination
#Example command, test it in your server using /hello
@bot.slash_command(name = "hello", description = "Say hello to the bot")
async def hello(ctx):
await ctx.respond("Hey!")
#another example, here the bot will provide a random number between 1 and 10.
@bot.slash_command(name = "random", description = "get a random number between 1 and 10")
async def random(ctx):
await ctx.respond(randint(1,10))
bot.run(TOKEN) #this line is what runs the bot itself