More converting

This commit is contained in:
Nikolaj Danger
2021-03-30 18:27:47 +02:00
parent e8c7fb95e5
commit a8a7e5eabd
7 changed files with 113 additions and 74 deletions

36
cogs/EventCog.py Normal file
View File

@ -0,0 +1,36 @@
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)")