-
Notifications
You must be signed in to change notification settings - Fork 731
Plugin APIs
The current version of BetterDiscord is deprecated and will only receive bug fixes. You may want to develop plugins for BetterDiscord v2 instead, however it is in active development and the plugin API has no documentation and is subject to change.
IMPORTANT: Name your plugins *.plugin.js
or they won't load.
Take a look at this prototypal Example Plugin or this class based Example for a template.
Checkout some of the plugins from the official BetterDiscord repository.
Currently available BdApi functions:
// Inject CSS to `head` element with identifier, don't forget to remove it on stop
BdApi.injectCSS(id, css);
// Clear your CSS
BdApi.clearCSS(id);
// Interact with other plugins
BdApi.getPlugin(pluginName);
// Get the BetterDiscord core module
BdApi.getCore();
// Save some information to disk (as JSON)
bdPluginStorage.set(pluginName, key, value);
// Get the stored information
bdPluginStorage.get(pluginName, key);
Some plugin developers have written their own libraries for developing plugins (some functions, such as monkey patching and accessing Discord's webpack modules are built into BDv2):
[1] Licensed under the MIT license
[2] Not licensed
There can be multiple files in the BetterDiscord plugins directory, but to prevent junk and prevent future collisions, it is best practice to include your entire plugin within one file.
BetterDiscord requires one line at the beginning of a plugin file to identify it:
//META{"name":"testPlugin"}*//
Be sure that testPlugin
matches the variable name defined in the file. Without this, your plugin will not be identified by BD properly and will not show up in the list.
Discord is Node.js and Chromium as one. BetterDiscord plugins can use all built-in Node.js functions and modules. It is possible to include pure JS modules within your plugin using webpack or any other JS module bundler. Native modules will work, but are not supported (at least until BDv2 is released) and you'll have to compile and distribute binaries for the following platforms:
- Windows 32-bit with Electron 1.6 (Node.js API version 53)
- Darwin (macOS) 64-bit with Electron 1.6 (Node.js API version 53)
- Linux 64-bit with Electron 1.6 (Node.js API version 53)
For Discord Canary (and likely PTB and stable soon) you'll need binaries for these platforms:
- Windows 32-bit with Electron 2.0 (Node.js API version 57)
- Darwin (macOS) 64-bit with Electron 2.0 (Node.js API version 57)
- Linux 64-bit with Electron 2.0 (Node.js API version 57)
By default, Discord will throttle plugins when it is minimised or otherwise not visible onscreen. Currently there are no in-plugin workarounds for this. Throttling is the same as Chromium, functions like setInterval
and setTimeout
will be throttled to at least 1000ms.
When using jQuery and listening on events like $(document).on('dblclick', ...)
, use a namespace such as $(document).on('dblclick.myplugin', ...)
in order to easily unload all events with $(document).off('dblclick.myplugin')
or $(document).off('*.myplugin')
without affecting Discord and other plugins.