Add error handler
This commit is contained in:
parent
e37e0e3a72
commit
9ab34e3362
28
run.py
28
run.py
@ -5,6 +5,8 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
|
import random
|
||||||
|
|
||||||
# Import custom files
|
# Import custom files
|
||||||
from src.config.config import LoadConfig
|
from src.config.config import LoadConfig
|
||||||
@ -31,6 +33,32 @@ class SebiMachine(commands.Bot, LoadConfig):
|
|||||||
if self.maintenance:
|
if self.maintenance:
|
||||||
print('MAINTENANCE ACTIVE')
|
print('MAINTENANCE ACTIVE')
|
||||||
|
|
||||||
|
async def on_command_error(self, ctx, error):
|
||||||
|
"""
|
||||||
|
The event triggered when an error is raised while invoking a command.
|
||||||
|
ctx : Context
|
||||||
|
error : Exception
|
||||||
|
"""
|
||||||
|
jokes = ["I\'m a bit tipsy, I took to many screenshots...",
|
||||||
|
"I am rushing to the 24/7 store to get myself anti-bug spray...",
|
||||||
|
"Organizing turtle race...",
|
||||||
|
"There is no better place then 127.0.0.1...",
|
||||||
|
"Recycling Hex Decimal...",
|
||||||
|
"No worry, I get fixed :^)...",
|
||||||
|
"R.I.P, press F for respect...",
|
||||||
|
"The bug repellent dit not work...",
|
||||||
|
"You found a bug in the program. Unfortunately the joke did not fit here, better luck next time..."]
|
||||||
|
|
||||||
|
# catch error
|
||||||
|
error = error.__cause__ or error
|
||||||
|
tb = traceback.format_exception(type(error), error, error.__traceback__, limit=1, chain=False)
|
||||||
|
tb = ''.join(tb)
|
||||||
|
joke = random.choice(jokes)
|
||||||
|
fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n```py\n{tb}\n```'
|
||||||
|
simple_fmt = f'**`{self.defaultprefix}{ctx.command}`**\n{joke}\n\n**{type(error).__name__}:**:\n**`{error}`**'
|
||||||
|
await ctx.send(fmt)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
client = SebiMachine()
|
client = SebiMachine()
|
||||||
# Make sure the key stays private.
|
# Make sure the key stays private.
|
||||||
|
|||||||
@ -78,5 +78,14 @@ class Upload:
|
|||||||
else:
|
else:
|
||||||
await ctx.send(f'Loaded `{extension}`.')
|
await ctx.send(f'Loaded `{extension}`.')
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def gitserver(self, ctx):
|
||||||
|
"""Pull latest commits, TMP until we have a solution"""
|
||||||
|
if ctx.author.id not in self.bot.ownerlist:
|
||||||
|
return await ctx.send('Only my creator can use me like this :blush:', delete_after=1)
|
||||||
|
import os
|
||||||
|
pull = os.popen('git pull').read()
|
||||||
|
await ctx.send(f'Pull complete\n```sh\n{pull}\n```')
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Upload(bot))
|
bot.add_cog(Upload(bot))
|
||||||
Loading…
x
Reference in New Issue
Block a user