36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
from discord.ext import commands
|
|
|
|
class EventCog(commands.cog):
|
|
def __init__(bot):
|
|
self.bot = bot
|
|
|
|
# Sets the game and logs when the bot logs in
|
|
@client.event
|
|
async def on_ready():
|
|
logThis("Logged in as "+client.user.name+", "+str(client.user.id))
|
|
game = discord.Game("Some weeb shit")
|
|
await client.change_presence(activity=game)
|
|
|
|
# Logs when user sends a command
|
|
@client.event
|
|
async def on_slash_command(ctx):
|
|
logThis(f"{ctx.author.display_name} ran {ctx.name}")
|
|
|
|
# Logs if a command experiences an error
|
|
@client.event
|
|
async def on_slash_command_error(ctx, error):
|
|
if isinstance(error, commands.CommandNotFound):
|
|
await ctx.send("That's not a command (error code 001)")
|
|
elif isinstance(error,commands.errors.MissingRequiredArgument):
|
|
logThis(f"{error}",str(ctx.channel_id))
|
|
await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.")
|
|
else:
|
|
exception = traceback.format_exception(type(error), error, error.__traceback__)
|
|
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
|
|
if stopAt in exception:
|
|
index = exception.index(stopAt)
|
|
exception = exception[:index]
|
|
|
|
exceptionString = "".join(exception)
|
|
logThis([f"exception in {ctx.name} command", f"{exceptionString}"],str(ctx.channel_id), 40)
|
|
await ctx.send("Something went wrong (error code 000)") |