Skip to content
sharkbound edited this page Sep 3, 2022 · 5 revisions

index

IMPORTANT NOTE ABOUT MODS:

__init__ for mod classes cannot take any parameters other than self

about

Mods are reloadable modules the bot loads on start from the mods folder

Mods are classes that are passed all events, like decorator event handler, but the difference is that mods are reloadable, and they can contain extra data in self since they are a custom class

defining a mod

to define a mod, create a python file in the mods folder, the mods folder can be found in the bot's working directory AKA where it was started from

it should look like this:

mods
- mymod.py

in mods/mymod.py create a class that imports and inherits the Mod class

dont forget to set the mods name using name = 'NAME_HERE' inside of the class

from twitchbot import Mod

class MyMod(Mod):
    name = 'mymod'

handle bot events using mods

Mods are passed the same events as decorator events, but are overriden a bit differently

mod events are overridden via standard method overriding in python by subclassing Mod class

continuing the example above, lets handle privmsg_received event and make the bot reply to "hello" messages

from twitchbot import Message, Mod

class MyMod(Mod):
    name = 'mymod'

    async def on_privmsg_received(self, msg: Message):
        if 'hello' in msg.content:
            await msg.reply(f'hello {msg.author}!')

all other events for mods can be seen by looking at the Mod source file

running the bot saying hello in chat will now make the bot greet the user, example response:

john doe: hello bot
bot: hello john doe!

all events in mods are overriden in this fashion

mod unique events

mods have the unique events loaded, unloaded, on_enabled and on_disabled

loaded:

triggers when the mod is initially loaded, does not have any parameters

unloaded

triggers when the mod is unloaded, does not have any parameters

on_enable:

triggers when the mod is enabled in a channel, gets passed the channels name as a string parameter

on_disable

triggers when the mod is disabled in a channel, gets passed the channels name as a string parameter

reloading mods

mods can be reloaded using !reloadmod <mod name, ex: !reloadmod mymod, the mod name after !reloadmod has to match the mods name after name = ... in the Mod's class