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.
BdApi.Logger is a helper class for logging data in a consistent and styled way. It supports multiple log levels and can be bound to a plugin name.
Constructor
new BdApi.Logger(
pluginName?: string,
nameStyle?: string,
messageStyle?: string
)
Name of the plugin. When provided, the logger is bound to this name and won’t require it in method calls.
nameStyle
string
default:"color: #3a71c1; font-weight: 700;"
CSS to style the plugin name in console output
CSS to style the main message in console output
// Unbound logger (requires plugin name in each call)
BdApi.Logger.log("MyPlugin", "This is a message");
// Bound logger (plugin name stored)
const logger = new BdApi.Logger("MyPlugin");
logger.log("This is a message");
// Custom styling
const styledLogger = new BdApi.Logger(
"MyPlugin",
"color: #ff0000; font-weight: bold;",
"color: #00ff00;"
);
Methods
log
Logs a basic informational message.
logger.log(pluginName: string, ...message: any[])
logger.log(...message: any[]) // When bound to a plugin
Name of the calling module (not required when logger is bound)
// Unbound
BdApi.Logger.log("MyPlugin", "User logged in", {userId: 123});
// Bound
const logger = new BdApi.Logger("MyPlugin");
logger.log("User logged in", {userId: 123});
debug
Logs a debug message for development purposes.
logger.debug(pluginName: string, ...message: any[])
logger.debug(...message: any[]) // When bound to a plugin
Name of the calling module (not required when logger is bound)
const logger = new BdApi.Logger("MyPlugin");
logger.debug("Cache state:", cache);
info
Logs an informational message.
logger.info(pluginName: string, ...message: any[])
logger.info(...message: any[]) // When bound to a plugin
Name of the calling module (not required when logger is bound)
const logger = new BdApi.Logger("MyPlugin");
logger.info("Plugin initialized successfully");
warn
Logs a warning message.
logger.warn(pluginName: string, ...message: any[])
logger.warn(...message: any[]) // When bound to a plugin
Name of the calling module (not required when logger is bound)
const logger = new BdApi.Logger("MyPlugin");
logger.warn("Deprecated API usage detected");
error
Logs an error message.
logger.error(pluginName: string, ...message: any[])
logger.error(...message: any[]) // When bound to a plugin
Name of the calling module (not required when logger is bound)
const logger = new BdApi.Logger("MyPlugin");
logger.error("Failed to load settings", error);
stacktrace
Logs an error with a collapsed error group showing the full stacktrace.
logger.stacktrace(
pluginName: string,
message: any,
error: Error
)
logger.stacktrace(message: any, error: Error) // When bound
Name of the calling module (not required when logger is bound)
Message or error to have logged
Error object to log with the message
const logger = new BdApi.Logger("MyPlugin");
try {
riskyOperation();
} catch (error) {
logger.stacktrace("Operation failed", error);
}
Usage examples
Bound logger in a plugin
module.exports = class MyPlugin {
constructor() {
this.logger = new BdApi.Logger("MyPlugin");
}
start() {
this.logger.info("Plugin started");
try {
this.initialize();
} catch (error) {
this.logger.stacktrace("Initialization failed", error);
}
}
stop() {
this.logger.info("Plugin stopped");
}
};
Unbound logger for quick logging
BdApi.Logger.log("MyPlugin", "Quick log message");
BdApi.Logger.warn("MyPlugin", "Something looks wrong");
BdApi.Logger.error("MyPlugin", "An error occurred");