🥅 - Commands errors are now treaded in a better way.

This commit is contained in:
Florian SYLVAIN
2021-03-09 18:59:51 +01:00
parent 334cfce8fb
commit aaec2a4bdf
5 changed files with 129 additions and 173 deletions
+15 -21
View File
@@ -1,13 +1,16 @@
from private import TOKEN_BOT
from time import time
from datetime import datetime
from discord.ext import commands
import discord
bot = commands.Bot(command_prefix='$')
startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"]
time_s = time()
print('Loading started')
@bot.event
async def on_ready():
default_activity = discord.Activity(type=discord.ActivityType.listening, name='$help')
@@ -16,33 +19,24 @@ async def on_ready():
' in ' + str(round(time() - time_s, 2)) + 's.')
@bot.command(hidden=True)
@bot.event
async def on_command_error(ctx, error):
print(datetime.now().strftime("[%H:%M:%S]") + ' \'' + str(error) + '\' from ' + str(ctx.author) + ' on ' + ctx.message.guild.name + '.')
await ctx.send(error)
@bot.command(hidden=True, ignore_extra=False)
@commands.is_owner()
async def loadext(ctx, extension):
try:
bot.load_extension(extension)
await ctx.send(str(extension) + ' successfully loaded.')
except discord.ext.commands.ExtensionNotFound:
await ctx.send('Extension not found.')
except discord.ext.commands.ExtensionAlreadyLoaded:
await ctx.send('Extension already loaded.')
except discord.ext.commands.NoEntryPointError as a:
await ctx.send(a)
except ExtensionFailed as b:
await ctx.send(b)
bot.load_extension(extension)
await ctx.send("Extension loaded.")
@bot.command(hidden=True)
@bot.command(hidden=True, ignore_extra=False)
@commands.is_owner()
async def unloadext(ctx, extension):
try:
bot.unload_extension(extension)
await ctx.send(str(extension) + ' successfully unloaded.')
except discord.ext.commands.ExtensionNotFound:
await ctx.send('Extension not found.')
except discord.ext.commands.ExtensionNotLoaded:
await ctx.send('Extension not loaded.')
bot.unload_extension(extension)
await ctx.send("Extension unloaded.")
if __name__ == "__main__":
for extension in startup_extensions: