shadow-core
Version:
A modular core framework for Discord bot development, providing commands, buttons, menus, middleware, and more.
34 lines (33 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ButtonManager = void 0;
const util_1 = require("../util");
class ButtonManager {
constructor(client) {
this.client = client;
}
registerButton(button) {
ButtonManager.buttons.set(button.customId, button);
}
async handleInteraction(interaction) {
let button;
if (interaction.customId.includes(":")) {
const parsedId = (0, util_1.splitSpecialId)(interaction.customId);
const newId = `${parsedId.feature}:${parsedId.action}:{id}`;
button = ButtonManager.buttons.get(newId);
}
else {
button = ButtonManager.buttons.get(interaction.customId);
}
if (button) {
await button.run(interaction, this.client);
}
}
static LogAllButtons() {
for (const [id, button] of ButtonManager.buttons) {
console.log(`Button ID: ${id}, Button Data:`, button);
}
}
}
exports.ButtonManager = ButtonManager;
ButtonManager.buttons = new Map();