n8n-nodes-discord-dnd 0.1.72 → 0.1.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class DiscordAction implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DiscordAction = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const voice_1 = require("@discordjs/voice");
6
+ const client_1 = require("./client");
7
+ const DiscordIntentMapping_1 = require("../definitions/DiscordIntentMapping");
8
+ class DiscordAction {
9
+ constructor() {
10
+ this.description = {
11
+ displayName: 'Discord Action',
12
+ name: 'discordAction',
13
+ icon: 'file:../assets/icon/discord.svg',
14
+ group: ['output'],
15
+ version: 1,
16
+ description: 'Perform Discord voice channel operations',
17
+ defaults: {
18
+ name: 'Discord Action',
19
+ },
20
+ inputs: ['main'],
21
+ outputs: ['main'],
22
+ credentials: [
23
+ {
24
+ name: 'discordApi',
25
+ required: true,
26
+ },
27
+ ],
28
+ properties: [
29
+ {
30
+ displayName: 'Operation',
31
+ name: 'operation',
32
+ type: 'options',
33
+ options: [
34
+ {
35
+ name: 'Join Voice Channel',
36
+ value: 'joinVoiceChannel',
37
+ description: 'Join a voice channel',
38
+ },
39
+ {
40
+ name: 'Leave Voice Channel',
41
+ value: 'leaveVoiceChannel',
42
+ description: 'Leave the current voice channel',
43
+ },
44
+ ],
45
+ default: 'joinVoiceChannel',
46
+ required: true,
47
+ },
48
+ {
49
+ displayName: 'Guild ID',
50
+ name: 'guildId',
51
+ type: 'string',
52
+ default: '',
53
+ required: true,
54
+ description: 'The ID of the Discord server (guild)',
55
+ },
56
+ {
57
+ displayName: 'Channel ID',
58
+ name: 'channelId',
59
+ type: 'string',
60
+ default: '',
61
+ displayOptions: {
62
+ show: {
63
+ operation: ['joinVoiceChannel'],
64
+ },
65
+ },
66
+ required: true,
67
+ description: 'The ID of the voice channel to join',
68
+ },
69
+ ],
70
+ };
71
+ }
72
+ async execute() {
73
+ const credentials = await this.getCredentials('discordApi');
74
+ const operation = this.getNodeParameter('operation', 0);
75
+ const guildId = this.getNodeParameter('guildId', 0);
76
+ // Initialize Discord client with voice intents
77
+ const clientOptions = (0, DiscordIntentMapping_1.getclientOptions)('voice');
78
+ const client = await (0, client_1.initializeDiscordClient)(credentials.botToken, clientOptions);
79
+ try {
80
+ const guild = await client.guilds.fetch(guildId);
81
+ if (!guild) {
82
+ throw new Error(`Could not find guild with ID ${guildId}`);
83
+ }
84
+ switch (operation) {
85
+ case 'joinVoiceChannel': {
86
+ const channelId = this.getNodeParameter('channelId', 0);
87
+ const channel = await guild.channels.fetch(channelId);
88
+ if (!channel || !(channel instanceof discord_js_1.VoiceChannel)) {
89
+ throw new Error(`Channel ${channelId} is not a voice channel`);
90
+ }
91
+ // Check bot permissions
92
+ const permissions = channel.permissionsFor(client.user);
93
+ if (!(permissions === null || permissions === void 0 ? void 0 : permissions.has(discord_js_1.PermissionsBitField.Flags.Connect))) {
94
+ throw new Error('Bot does not have permission to join this voice channel');
95
+ }
96
+ if (!(permissions === null || permissions === void 0 ? void 0 : permissions.has(discord_js_1.PermissionsBitField.Flags.Speak))) {
97
+ throw new Error('Bot does not have permission to speak in this voice channel');
98
+ }
99
+ // Create connection
100
+ const connection = (0, voice_1.joinVoiceChannel)({
101
+ channelId: channel.id,
102
+ guildId: guild.id,
103
+ adapterCreator: guild.voiceAdapterCreator,
104
+ selfDeaf: false,
105
+ selfMute: false,
106
+ });
107
+ // Create an audio player to keep the connection alive
108
+ const player = (0, voice_1.createAudioPlayer)();
109
+ connection.subscribe(player);
110
+ try {
111
+ // Wait for the connection to be ready with a timeout
112
+ await Promise.race([
113
+ (0, voice_1.entersState)(connection, voice_1.VoiceConnectionStatus.Ready, 30000),
114
+ new Promise((_, reject) => {
115
+ connection.on(voice_1.VoiceConnectionStatus.Disconnected, () => {
116
+ reject(new Error('Voice connection was disconnected'));
117
+ });
118
+ connection.on('error', (error) => {
119
+ reject(error);
120
+ });
121
+ }),
122
+ ]);
123
+ }
124
+ catch (error) {
125
+ // Clean up if connection fails
126
+ connection.destroy();
127
+ throw new Error(`Failed to join voice channel: ${(error === null || error === void 0 ? void 0 : error.message) || 'Unknown error'}`);
128
+ }
129
+ break;
130
+ }
131
+ case 'leaveVoiceChannel': {
132
+ const connection = (0, voice_1.getVoiceConnection)(guildId);
133
+ if (connection) {
134
+ connection.destroy();
135
+ }
136
+ break;
137
+ }
138
+ default:
139
+ throw new Error(`The operation "${operation}" is not supported!`);
140
+ }
141
+ // Clean up: Destroy the client after operation is complete
142
+ client.destroy();
143
+ // Return success with additional details
144
+ return [this.helpers.returnJsonArray({
145
+ success: true,
146
+ operation,
147
+ guildId,
148
+ channelId: operation === 'joinVoiceChannel' ? this.getNodeParameter('channelId', 0) : undefined
149
+ })];
150
+ }
151
+ catch (error) {
152
+ // Clean up on error
153
+ client.destroy();
154
+ throw error;
155
+ }
156
+ }
157
+ }
158
+ exports.DiscordAction = DiscordAction;
159
+ //# sourceMappingURL=DiscordAction.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DiscordAction.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordAction.node.ts"],"names":[],"mappings":";;;AAMA,2CAAoF;AACpF,4CAO0B;AAC1B,qCAAmD;AACnD,8EAAuE;AAEvE,MAAa,aAAa;IAA1B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,gBAAgB;YAC7B,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,iCAAiC;YACvC,KAAK,EAAE,CAAC,QAAQ,CAAC;YACjB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,0CAA0C;YACvD,QAAQ,EAAE;gBACT,IAAI,EAAE,gBA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,EAAE;wBACf,UAAU,CAAC,OAAO,EAAE,CAAC;qBACrB;oBACD,MAAM;iBACN;gBAED;oBACC,MAAM,IAAI,KAAK,CAAC,kBAAkB,SAAS,qBAAqB,CAAC,CAAC;aACnE;YAED,2DAA2D;YAC3D,MAAM,CAAC,OAAO,EAAE,CAAC;YAEjB,yCAAyC;YACzC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;oBACpC,OAAO,EAAE,IAAI;oBACb,SAAS;oBACT,OAAO;oBACP,SAAS,EAAE,SAAS,KAAK,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;iBAC/F,CAAC,CAAC,CAAC;SAEJ;QAAC,OAAO,KAAK,EAAE;YACf,oBAAoB;YACpB,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,KAAK,CAAC;SACZ;IACF,CAAC;CACD;AAlKD,sCAkKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-discord-dnd",
3
- "version": "0.1.72",
3
+ "version": "0.1.74",
4
4
  "description": "n8n node to create triggers for Discord events",
5
5
  "keywords": [
6
6
  "n8n",
@@ -33,7 +33,8 @@
33
33
  "dist/credentials/DiscordApi.credentials.js"
34
34
  ],
35
35
  "nodes": [
36
- "dist/nodes/DiscordTrigger.node.js"
36
+ "dist/nodes/DiscordTrigger.node.js",
37
+ "dist/nodes/DiscordAction.node.js"
37
38
  ]
38
39
  },
39
40
  "devDependencies": {
@@ -48,7 +49,10 @@
48
49
  "typescript": "~5.0.4"
49
50
  },
50
51
  "dependencies": {
52
+ "@discordjs/opus": "^0.10.0",
53
+ "@discordjs/voice": "^0.16.1",
51
54
  "discord.js": "^14.9.0",
55
+ "libsodium-wrappers": "^0.7.15",
52
56
  "n8n-core": "~1.5.0"
53
57
  }
54
58
  }