A Pycord Template with some example!
Getting Started:
- Clone this repository using
git clone https://github.com/AungS8430/pycord-template.git
- If you have discord.py installed, please do
pip uninstall discord.py
first. - You must have Python 3.8 or above installed ( I use Python 3.8.12).
- Do
pip install -r requirements.txt
to install requirements. 5. Go to .env.example
, remove .example and insert your bot's token and welcome channel ID into the file. You must keep your bot's token private! 6. To run this basic bot, run
python 3.8 main.py
in the same directory as your bot.
Adding Commands or Events:
Add commands:
- Create a new Python file in
/cogs/commands
- Add this code in the file
import discord
from discord.ext import commands, tasks
from discord.commands import slash_command, Option #, SlashCommandGroup if you want to create a category.
class CogName(commands.Cog): # Replace 'CogName' with your cog name.
def __init__(self, bot):
self.bot = bot
category = SlashCommandGroup('Category name', 'Category description')
@slash_command( #change it into @category.command( if you use category.
name='command name here',
description='commnad description here',
)
async def commandname(self, ctx, option: Option(str, 'This is option', required=True)):
embed = discord.Embed(
title='hello',
description=f'{option}',
color=discord.Color.green()
)
await ctx.respond(embed=embed)
def setup(bot):
bot.add_cog(CogName(bot))
- Add the file directory into
main.py
in this formatcogs.commands.filename
Add event:
- Create a new Python file in
/cogs/events
- Add this code in the file
import discord
from discord.ext import commands, tasks
class CogName(commands.Cog): # Replace 'CogName' with your cog name.
def __init__(self, bot):
self.bot = bot
@command.Cog.listener()
async def eventname(self, ...):
# do something
def setup(bot):
bot.add_cog(CogName(bot))
- Add the file directory into
main.py
in this formatcogs.event.filename