📝 Cogs and utils
Improved code style and added comments and docstrings to cogs and utils.
This commit is contained in:
@ -1,34 +1,40 @@
|
||||
from discord.ext import commands
|
||||
"""Contains the EventCog, which runs code for specific bot events."""
|
||||
from discord.ext import commands # Has the cog class
|
||||
|
||||
|
||||
class EventCog(commands.Cog):
|
||||
"""Handles bot events."""
|
||||
|
||||
def __init__(self, bot):
|
||||
"""Initialize the bot."""
|
||||
self.bot = bot
|
||||
self.bot.on_error = self.on_error
|
||||
|
||||
# Syncs commands, sets the game, and logs when the bot logs in
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
"""Log and set bot status when bot logs in."""
|
||||
await self.bot.eventHandler.on_ready()
|
||||
|
||||
# Logs when user sends a command
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command(self, ctx):
|
||||
"""Log when a slash command is run."""
|
||||
await self.bot.eventHandler.on_slash_command(ctx)
|
||||
|
||||
# Logs if a command experiences an error
|
||||
@commands.Cog.listener()
|
||||
async def on_slash_command_error(self, ctx, error):
|
||||
"""Log when a slash error occurs."""
|
||||
await self.bot.errorHandler.on_slash_command_error(ctx, error)
|
||||
|
||||
# Logs if on error occurs
|
||||
async def on_error(self, method, *args, **kwargs):
|
||||
"""Log when an error occurs."""
|
||||
await self.bot.errorHandler.on_error(method)
|
||||
|
||||
# If someone reacted to a message, checks if it's a reaction it's
|
||||
# Gwendolyn has been waiting for, and then does something
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_add(self, reaction, user):
|
||||
"""Handle when someone reacts to a message."""
|
||||
await self.bot.eventHandler.on_reaction_add(reaction, user)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
"""Add the eventcog to the bot."""
|
||||
bot.add_cog(EventCog(bot))
|
||||
|
Reference in New Issue
Block a user