Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

discord.py main file setup

# all commands that you make should be in a folder called 'cogs'

import discord
from discord.ext import commands

import os

client = commands.Bot(command_prefix = '>')
client.remove_command('help')

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Game(">help"))
    print('Logged in as ' + client.user.name)

@client.event
async def on_command_error(ctx , error):
    if isinstance(error, commands.CommandNotFound):
        await ctx.send('Command not found.')
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send('Missing required argument.')
    elif isinstance(error, discord.ext.commands.errors.MissingPermissions) or isinstance(error , discord.Forbidden):
        await ctx.send('You do not have permission to use this command.')
    else:
        await ctx.send('An error has occured: ' + error)

@client.command()
async def load(extension):
    client.load_extension(f'cogs.{extension}')

@client.command()
async def unload(extension):
    client.unload_extension(f'cogs.{extension}')

for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        client.load_extension(f'cogs.{filename[:-3]}')

client.run('TOKEN')
Comment

PREVIOUS NEXT
Code Example
Python :: how to scrape data from github api python 
Python :: python entry element 
Python :: install pythong to custom location 
Python :: ring Sort List Item 
Python :: ring open another file 
Python :: ring define private attributes and methods 
Python :: store image in django postprocessimage in django storage 
Python :: for loop the string from reverse order and skipping last element in string python 
Python :: python rational numbers 
Python :: ring Creating Reports using the WebLib and the GUILib 
Python :: Use miraculous with enviroment variable token 
Python :: cuantas palabras hay en una frase en python 
Python :: OfficeApi 
Python :: player to walk on the surface 
Python :: Print the numbers assigned to the list values in python 
Python :: django save another class data while saving a class 
Python :: python if not explaned 
Python :: long type python 
Python :: alterning format when reading from a text file 
Python :: python notification image 
Python :: view does not return httpresponse 
Python :: seaborn heatmap spearman correlation coefficient 
Python :: how to make an instagram report bot python 
Python :: any(iterable) 
Python :: django file field from base64 
Python :: python RandomForest 
Python :: python inline assignment 
Python :: python if block 
Python :: accessing list elements in python 
Python :: all python 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =