Skip to content

Plugin

External plugins (standalone .nkplugin.js files) are loaded from the (nekocord data)/plugins directory when nekocord starts.

Plugin Interface

Each .nkplugin.js file has a single default export (in CommonJS format) that is a class that implements this interface.

info

type: PluginInfo

The info property is an object that contains metadata about the plugin.

onEnable

type: () => void

This method is called once on startup if the plugin was previously enabled, and also called each time the user manually toggles it on in the settings.

onDisable

type: () => void

This method is called when the plugin is disabled (if the user manually toggles it off in the settings). Note that this method is not called when nekocord is shutting down.

onRegister

type: () => void

This method is called once when the plugin is registered, whether it is enabled or not.

onPreferencesChange

type: (userPreferences: Record<string, any>) => void

This method is called once when registered and also when the user’s preferences are updated. The userPreferences parameter is an object containing the user’s preferences for the plugin.

PluginInfo Interface

The info property of a plugin implements this interface. It contains metadata about the plugin.

name

type: string

The name of the plugin.

description

type: string

A brief description of the plugin.

id

type: string

The unique identifier of the plugin. This should be in the format author:plugin-name. Note that certain values for author can be reserved for certain repositories only.

authors

type: Author[]

An array of authors of the plugin.

version

type: string

The version of the plugin. Ideally, this should follow Semantic Versioning.

patches

type: Patch[]

An array of code patches to apply to Discord’s modules. See Creating Code Patches for more information.

type: Record<string, MenuPatch[]>

An object containing menu patches to apply to Discord’s menus. See Patching Menus for more information.

commands

type: Command[]

An array of commands to register with the plugin. See Command API for more information.

flux

type: Record<string, (e: any) => {}>

An object containing event handlers for Discord’s FluxDispatcher’s events. These handlers are called when the corresponding event is emitted.

preferences

type: [Preference[]](#preference-interface)

An array of preferences for the plugin.

hidePreferences

type: boolean default: false

Whether to hide the default preferences UI for the plugin. Can be useful if you want to handle preferences entirely yourself.

renderPreferences

type: () => React.ReactNode

A function that returns a React element to render the preferences UI for the plugin. If defined, this will appear above the default preferences UI, if not hidden.

css

type: string

A string containing CSS to inject into Discord when the plugin is enabled.