Skip to content

Setting up an event listner

Logicguy edited this page Jan 1, 2023 · 2 revisions

All events live in /bot/events, the filename you use can be anything eg. reaction_add, member_join etc.

To register an event define a class within your file named event, here is an example

# /bot/events/reaction_add.py
from bot.config import Config, Embed
from bot.base import Event

class event(Event):
    """ A discord event instance. """

    name = "on_raw_reaction_add"

    async def execute(self, payload) -> None:
        print(payload)

Here we define a on_raw_reaction_add event that gets triggered every time a reaction is added to a message.

The event name is the event that it should listen on.

In the object a self.bot, self.db and self.manager is also exposed in case you need to access those.

See #accessing-the-database for more info on database usage

The execute function gets called every time the event name is triggered, you should add what ever arguments are listed in the documentation just remember to add self as the first argument as we are working with a class.