@globalart/nestcord
Version:
A module for creating Discord bots using NestJS, based on Discord.js
51 lines (50 loc) • 2.61 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlashCommandsModule = void 0;
const common_1 = require("@nestjs/common");
const slash_commands_service_1 = require("./slash-commands.service");
const discord_js_1 = require("discord.js");
const nestcord_explorer_service_1 = require("../../nestcord-explorer.service");
const decorators_1 = require("./decorators");
let SlashCommandsModule = class SlashCommandsModule {
constructor(client, explorerService, slashCommandsService) {
this.client = client;
this.explorerService = explorerService;
this.slashCommandsService = slashCommandsService;
}
onModuleInit() {
this.explorerService.explore(decorators_1.SlashCommand.KEY).forEach((command) => this.slashCommandsService.add(command));
return this.explorerService
.explore(decorators_1.Subcommand.KEY)
.forEach((subcommand) => this.slashCommandsService.addSubCommand(subcommand));
}
onApplicationBootstrap() {
return this.client.on('interactionCreate', (i) => {
var _a;
if (!i.isChatInputCommand() && !i.isAutocomplete()) {
return;
}
return (_a = this.slashCommandsService.get(i.commandName)) === null || _a === void 0 ? void 0 : _a.execute(i);
});
}
};
exports.SlashCommandsModule = SlashCommandsModule;
exports.SlashCommandsModule = SlashCommandsModule = __decorate([
(0, common_1.Global)(),
(0, common_1.Module)({
providers: [slash_commands_service_1.SlashCommandsService],
exports: [slash_commands_service_1.SlashCommandsService],
}),
__metadata("design:paramtypes", [discord_js_1.Client,
nestcord_explorer_service_1.ExplorerService,
slash_commands_service_1.SlashCommandsService])
], SlashCommandsModule);