Skip to content

Commit 6e72a09

Browse files
authored
Merge pull request #1 from JoeBanks13/patch-1
Added command logging *and* error handling
2 parents afa71c8 + 787a193 commit 6e72a09

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

arbot.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from discord.ext import commands
22
import secrets
3-
3+
import traceback
44
from datetime import datetime
55

66
description = '''An example arbot to showcase the discord.ext.commands extension
@@ -19,6 +19,17 @@ async def on_ready():
1919
print(arbot.user.name)
2020
print('Servers: ' + ', '.join([str(s) for s in arbot.servers]))
2121
print('------')
22+
23+
@arbot.event
24+
async def on_command(s,e):
25+
print("{0.name} used >{1} in {2.name} (Channel #{3})".format(e.message.author,s,e.message.server,e.message.channel))
26+
27+
@arbot.event
28+
async def on_command_error(error,ctx):
29+
em = discord.Embed(title="An Error occured",description="Sorry but I couldn't process that command properely",color=discord.Color.red())
30+
await bot.send_message(ctx.message.channel,embed=em)
31+
tb = "\n".join(traceback.format_tb(error.original.__traceback__))
32+
print("{}: {}\n{}".format(error.original.__class__.__name__,str(error),str(tb)))
2233

2334
@arbot.command()
2435
async def load(extension_name : str):
@@ -62,4 +73,4 @@ async def ti():
6273
exc = '{}: {}'.format(type(e).__name__, e)
6374
print('Failed to load extension {}\n{}'.format(extension, exc))
6475

65-
arbot.run(secrets.BOT_TOKEN)
76+
arbot.run(secrets.BOT_TOKEN)

0 commit comments

Comments
 (0)