Plugins
Esta página aún no está disponible en tu idioma.
Installation
Chances are, you just want your bot to work. Plugins can preprocess and create reusable conditions for modules.
To install plugins, you can use the CLI:
- Install your favorite(s) (or the ones that look the coolest). In my imaginary mind, I installed the
ownerOnly
plugin. (This should install tosrc/plugins
) - Add the plugin to your module in the
plugins
field.
┗|` O′|┛ perfect, your first plugin!
Creating Plugins
Plugins are essentially functions that use the controller object to determine whether to continue or stop the execution of a command.
Controller Object
The controller object is passed into every plugin. It has two methods: next
and stop
.
Plugins use these methods to control the flow of the command. For example, if a plugin fails, it can call controller.stop()
to prevent the command from executing.
Init Plugins
Init plugins modify how commands are loaded or do preprocessing.
An instance of Controller
(as seen above) is passed into every plugin. This controls whether a module is stored into sern.
Event Plugins
- An event is emitted by
discord.js
. - This event is passed to all plugins (in order!!),
- If all are successful, the command is executed.
Can you predict the behavior of this command?
- Before loading into sern, this command module will check if this module is in the correct directory:
other
. - Before an event occurs, this command module will check if the user has the id
182326315813306368
. - If all plugins return
controller.next()
, this command repliesPong 🏓