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). I installed the
ownerOnly
plugin. - Thank the creator of the plugin. (mandatory)
- 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.
Init Plugins
Init plugins modify how commands are loaded or do preprocessing.
You may modify any of the fields of the module, but please careful! This also includes double checking any plugins which may modify fields of modules.
User Data
Each module has a locals
object which you are free to add custom user data. For example, the localizer AND publisher
take advantage of this to attach metadata.
Control Plugins
- An event is emitted by
discord.js
. - This event is passed to all control plugins in order!!,
- If all are successful, the command is executed.
Controller Object
The controller object is passed into every plugin. It has two methods: next
and stop
.
Plugins use the controller to control the flow of the command. For example, if a plugin fails, it calls controller.stop()
to prevent the command from executing.
State
SDT = state, dependencies, type (very creative)
Plugins can recieve data from previous plugins. State is created when controller.next
is called with a record.
If all control plugins are successful, the final state is passed to the module execute
.
Caveats
Passing data with the same key will get overridden by the latest plugin. It is recommended to namespace data keys if you have multiple plugins, or you can ensure no keys are overridden by the plugin chain.
Dependencies
SDT = state, dependencies, type (very creative)
Plugins also carry an instance of all of your dependencies. Use them and use them as you please! For example, creating a plugin which logs which user uses your command