Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/betterdiscord/betterdiscord/llms.txt

Use this file to discover all available pages before exploring further.

UI is a utility class for creating user interfaces. It provides methods for showing modals, toasts, notices, and building settings panels.

Methods

alert

Shows a generic but very customizable modal.
BdApi.UI.alert("Warning", "This action cannot be undone!");

// With React elements
BdApi.UI.alert("Title", [
    "This is a ",
    BdApi.React.createElement("strong", {}, "bold"),
    " message."
]);
title
string
required
Title of the modal.
content
string | ReactElement | Array<string | ReactElement>
required
Content to display in the modal. Can be a string, React element, or array of both.

showConfirmationModal

Shows a generic but very customizable confirmation modal with optional confirm and cancel callbacks.
BdApi.UI.showConfirmationModal("Delete Item", "Are you sure you want to delete this?", {
    danger: true,
    confirmText: "Delete",
    cancelText: "Cancel",
    onConfirm: () => {
        console.log("Item deleted");
    },
    onCancel: () => {
        console.log("Deletion cancelled");
    }
});
title
string
required
Title of the modal.
content
string | ReactElement | Array<string | ReactElement>
required
Single or mixed array of React elements and strings. Everything is wrapped in Discord’s TextElement component so strings will show and render properly.
options
object
Options to modify the modal.
Returns: string - The key used for this modal

showChangelogModal

Shows a changelog modal in a similar style to Discord’s. Customizable with images, videos, colored sections and supports markdown.
BdApi.UI.showChangelogModal({
    title: "My Plugin v2.0",
    subtitle: "Major Update",
    blurb: "This update brings exciting new features!",
    banner: "https://example.com/banner.jpg",
    changes: [
        {
            title: "New Features",
            type: "added",
            items: [
                "Added dark mode support",
                "Added user customization options"
            ]
        },
        {
            title: "Bug Fixes",
            type: "fixed",
            items: [
                "Fixed crash on startup",
                "Fixed memory leak"
            ]
        },
        {
            title: "Improvements",
            type: "improved",
            items: [
                "Improved performance by 50%",
                "Better error messages"
            ]
        }
    ],
    footer: "Thank you for using my plugin!"
});
options
object
required
Information to display in the modal.
Returns: string - The key used for this modal

showInviteModal

Shows a modal for joining a guild like you would natively through Discord.
BdApi.UI.showInviteModal("discord-api");
inviteCode
string
required
The Discord invite code (without the discord.gg/ part).

showToast

Shows a toast notification similar to Android towards the bottom of the screen.
BdApi.UI.showToast("Settings saved!", {type: "success"});
BdApi.UI.showToast("An error occurred", {type: "error", timeout: 5000});
content
string
required
The string to show in the toast.
options
object
Options for the toast.

showNotice

Shows a notice above Discord’s chat layer.
const close = BdApi.UI.showNotice("Update available!", {
    type: "info",
    buttons: [
        {
            label: "Update Now",
            onClick: () => {
                console.log("Updating...");
                close();
            }
        },
        {
            label: "Dismiss",
            onClick: () => close()
        }
    ]
});
content
string | Node
required
Content of the notice.
options
object
Options for the notice.
Returns: function - A callback for closing the notice. Passing true as first parameter closes immediately without transitioning out

showNotification

Shows a system notification (if enabled in BetterDiscord settings).
BdApi.UI.showNotification({
    title: "New Message",
    content: "You have a new message from John",
    type: "info",
    icon: "https://example.com/icon.png",
    duration: 5000,
    actions: [
        {
            text: "View",
            callback: () => console.log("Viewing message")
        }
    ]
});
notificationObj
object
required
Notification configuration object.

createTooltip

Creates a tooltip to automatically show on hover.
const button = document.querySelector(".my-button");
const tooltip = BdApi.UI.createTooltip(button, "Click me!", {
    side: "top",
    style: "primary"
});
node
HTMLElement
required
DOM node to monitor and show the tooltip on.
content
string | HTMLElement
required
String or HTML element to show in the tooltip.
options
object
Additional options for the tooltip.
Returns: Tooltip - The tooltip that was generated

openDialog

Gives access to the Electron Dialog API. Returns a Promise that resolves to an object with the result.
// Open file dialog
const result = await BdApi.UI.openDialog({
    mode: "open",
    openFile: true,
    filters: [{name: "Images", extensions: ["png", "jpg", "gif"]}]
});

if (!result.cancelled) {
    console.log("Selected files:", result.filePaths);
}

// Save file dialog
const saveResult = await BdApi.UI.openDialog({
    mode: "save",
    defaultPath: "~/my-file.txt"
});

if (!saveResult.cancelled) {
    console.log("Save to:", saveResult.filePath);
}
options
object
required
Options object to configure the dialog.
Returns: Promise<object> - Promise that resolves to an object with:
  • cancelled (boolean): Whether the dialog was cancelled
  • filePath (string): Selected file path for save mode
  • filePaths (Array<string>): Selected file paths for open mode

buildSettingItem

Creates a single setting wrapped in a setting item that has a name and note.
const setting = BdApi.UI.buildSettingItem({
    type: "switch",
    id: "enable-feature",
    name: "Enable Feature",
    note: "Turns the feature on or off",
    value: true,
    onChange: (value) => {
        console.log("Setting changed:", value);
    }
});

document.body.appendChild(setting);
setting
object
required
Setting configuration object.
Returns: A SettingItem React element with an input as the child

buildSettingsPanel

Creates a settings panel (React element) based on JSON-like data.
const panel = BdApi.UI.buildSettingsPanel({
    settings: [
        {
            type: "category",
            id: "general",
            name: "General Settings",
            shown: true,
            settings: [
                {
                    type: "switch",
                    id: "enabled",
                    name: "Enable Plugin",
                    note: "Turns the plugin on or off",
                    value: true
                },
                {
                    type: "text",
                    id: "username",
                    name: "Username",
                    note: "Your username",
                    value: "John"
                }
            ]
        },
        {
            type: "slider",
            id: "volume",
            name: "Volume",
            note: "Adjust the volume",
            value: 50,
            min: 0,
            max: 100
        }
    ],
    onChange: (category, id, value) => {
        console.log(`Setting changed: ${category || 'root'}.${id} = ${value}`);
    }
});
props
object
required
Panel configuration object.
Returns: React element usable for a settings panel

Examples

Complete settings panel

class MyPlugin {
    getSettingsPanel() {
        return BdApi.UI.buildSettingsPanel({
            settings: [
                {
                    type: "category",
                    id: "appearance",
                    name: "Appearance",
                    settings: [
                        {
                            type: "switch",
                            id: "darkMode",
                            name: "Dark Mode",
                            note: "Enable dark mode",
                            value: this.settings.darkMode
                        },
                        {
                            type: "color",
                            id: "accentColor",
                            name: "Accent Color",
                            note: "Choose your accent color",
                            value: this.settings.accentColor
                        }
                    ]
                }
            ],
            onChange: (category, id, value) => {
                this.settings[id] = value;
                this.saveSettings();
            }
        });
    }
}

User feedback with toasts

function saveSettings() {
    try {
        // Save settings...
        BdApi.UI.showToast("Settings saved!", {type: "success"});
    } catch (error) {
        BdApi.UI.showToast("Failed to save settings", {type: "error"});
    }
}

Confirmation before destructive action

function deleteAllData() {
    BdApi.UI.showConfirmationModal(
        "Delete All Data",
        "This will permanently delete all your data. This action cannot be undone.",
        {
            danger: true,
            confirmText: "Delete Everything",
            onConfirm: () => {
                // Perform deletion
                BdApi.UI.showToast("All data deleted", {type: "success"});
            }
        }
    );
}