n8n-nodes-discord-self
Version:
n8n community nodes for Discord selfbot via discord.js-selfbot-v13 (use at your own risk)
93 lines • 3.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiscordSelf = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const ClientManager_1 = require("./ClientManager");
class DiscordSelf {
constructor() {
this.description = {
displayName: 'Discord Self',
name: 'discordSelf',
group: ['transform'],
version: 1,
description: '最小可用操作:发送消息到频道',
defaults: {
name: 'Discord Self',
},
inputs: ["main"],
outputs: ["main"],
credentials: [
{
name: 'discordSelfApi',
required: true,
},
],
properties: [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
noDataExpression: true,
default: 'sendMessage',
options: [{ name: 'Send Message', value: 'sendMessage' }],
},
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Content',
name: 'content',
type: 'string',
default: '',
required: true,
typeOptions: { rows: 4 },
},
],
};
}
async execute() {
var _a;
const items = this.getInputData();
const credentials = (await this.getCredentials('discordSelfApi'));
const token = credentials.token;
const client = await (0, ClientManager_1.getOrCreateClient)(token);
const returnItems = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
try {
const channelId = this.getNodeParameter('channelId', itemIndex, '');
const content = this.getNodeParameter('content', itemIndex, '');
if (!channelId || !content) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Channel ID 与 Content 均为必填');
}
const channel = await client.channels.fetch(channelId);
if (!channel || typeof channel.send !== 'function') {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), '指定的 Channel 不支持发送消息');
}
const sent = await channel.send(content);
returnItems.push({
json: {
id: sent === null || sent === void 0 ? void 0 : sent.id,
url: (_a = sent === null || sent === void 0 ? void 0 : sent.url) !== null && _a !== void 0 ? _a : null,
channelId: channelId,
content,
},
});
}
catch (error) {
if (this.continueOnFail()) {
returnItems.push({ json: { error: error.message } });
}
else {
throw error;
}
}
}
return [returnItems];
}
}
exports.DiscordSelf = DiscordSelf;
//# sourceMappingURL=DiscordSelf.node.js.map