Skip to main content
BdApi is a globally accessible object (window.BdApi) for use by plugins and developers. It provides a comprehensive set of tools for interacting with Discord’s internals and creating powerful plugins.

Accessing BdApi

There are two ways to access BdApi:

Global access

You can access the global API directly:
BdApi.showToast("Hello World!");

Plugin-scoped instance

When creating a plugin, you can get a scoped instance by passing your plugin name to the constructor. This automatically binds certain namespaces to your plugin:
const BdApi = new BdApi("MyPlugin");
Plugin-scoped instances automatically bind your plugin name to:
  • Patcher - All patches are tracked under your plugin name
  • Data - Data is saved/loaded under your plugin name
  • DOM - Styles use your plugin name as the default ID
  • Logger - Logs are prefixed with your plugin name
  • Commands - Commands are registered under your plugin
  • Hooks - React hooks are scoped to your plugin

API namespaces

Core modules

Patcher

Modify existing functions with before, instead, and after patches

Webpack

Search for and retrieve Discord’s internal modules

Data

Save and load persistent plugin data

DOM

Manipulate the DOM and inject styles

UI

Create modals, toasts, notices, and settings panels

Additional namespaces

  • React - The React module used inside Discord
  • ReactDOM - The ReactDOM module used inside Discord
  • ReactUtils - Utilities for working with React components
  • Utils - General utility functions
  • Components - Pre-built React components for common UI elements
  • ContextMenu - Tools for working with Discord’s context menus
  • Plugins - Manage installed plugins
  • Themes - Manage installed themes
  • Commands - Register custom slash commands
  • Net - Network utilities including fetch
  • Logger - Logging utilities
  • Hooks - React hooks

Properties

version
string
A reference string for BetterDiscord’s current version.

Example plugin structure

class MyPlugin {
    constructor() {
        this.BdApi = new BdApi("MyPlugin");
    }

    start() {
        this.BdApi.UI.showToast("Plugin started!");
        
        // Patches are automatically tracked
        this.BdApi.Patcher.after(SomeModule, "someFunction", (thisObject, args, returnValue) => {
            return returnValue;
        });
        
        // Data is automatically namespaced
        this.BdApi.Data.save("settings", {enabled: true});
    }

    stop() {
        // Automatically unpatch all patches for this plugin
        this.BdApi.Patcher.unpatchAll();
        this.BdApi.UI.showToast("Plugin stopped!");
    }
}

Build docs developers (and LLMs) love