n8n-nodes-discord
Version:
nodes to trigger workflows from Discord or send interactive messages. Uses the components API which allows to create dialogs (e.g. attach buttons and wait for the user to click on them)
65 lines • 2.72 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const discord_js_1 = require("discord.js");
const rest_1 = require("@discordjs/rest");
const imports = ['clean'];
const awaitingCommands = [];
imports.forEach((commandName) => {
const command = Promise.resolve().then(() => __importStar(require(`./${commandName}`)));
awaitingCommands.push(command);
});
async function default_1(token, clientId, client) {
const commands = await Promise.all(awaitingCommands);
console.log('commands', commands);
const rest = new rest_1.REST({ version: '10' }).setToken(token);
const parsedCommands = commands.map((e) => {
return e.default.command().toJSON();
});
console.log('parsedCommands', parsedCommands);
rest
.put(discord_js_1.Routes.applicationCommands(clientId), {
body: parsedCommands,
})
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
client.on('interactionCreate', async (interaction) => {
var _a;
if (!interaction.isChatInputCommand())
return;
const member = interaction.member;
if (!member.permissions.has('ADMINISTRATOR'))
return;
console.log('interactionCreate >>>>>>>>>>>>>>');
const { commandName, options } = interaction;
const i = imports.indexOf(commandName);
if (i === -1)
return;
const reply = await commands[i].default.reply((_a = options.get('input')) === null || _a === void 0 ? void 0 : _a.value, interaction);
interaction.reply(reply);
});
}
exports.default = default_1;
//# sourceMappingURL=index.js.map