UNPKG

nhandler

Version:

The easy to use, all-in-one command, event and component handler.

46 lines (45 loc) 1.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseHandler = exports.commandsToRegister = void 0; const node_events_1 = __importDefault(require("node:events")); exports.commandsToRegister = []; class BaseHandler extends node_events_1.default { constructor(debug) { super(); this.debug = debug; } setClient(client) { this.client = client; return this; } debugLog(...args) { this.emit("debug", ...args); if (this.debug) this.debug(...args); } async updateApplicationCommands(useDirectApi = false) { if (!this.client.application) { throw new Error("Application is not ready. Update application commands after the client has emitted 'ready'."); } this.debugLog("Updating application commands."); if (useDirectApi) { await fetch(`https://discord.com/api/v10/applications/${this.client.application.id}/commands`, { method: "PUT", body: JSON.stringify(exports.commandsToRegister), headers: { Authorization: `Bot ${this.client.token}`, "Content-Type": "application/json; charset=UTF-8", "User-Agent": "DiscordBot (https://github.com/discord/discord-example-app, 1.0.0)", }, }); } else { await this.client.application.commands.set(exports.commandsToRegister); } this.debugLog("Successfully updated application commands."); } } exports.BaseHandler = BaseHandler;