n8n-nodes-discord-dnd 0.1.72 → 0.1.73
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,138 @@
|
|
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
|
+
const connection = (0, voice_1.joinVoiceChannel)({
|
92
|
+
channelId: channel.id,
|
93
|
+
guildId: guild.id,
|
94
|
+
adapterCreator: guild.voiceAdapterCreator,
|
95
|
+
});
|
96
|
+
// Create an audio player to keep the connection alive
|
97
|
+
const player = (0, voice_1.createAudioPlayer)();
|
98
|
+
connection.subscribe(player);
|
99
|
+
// Wait for the connection to be ready
|
100
|
+
await new Promise((resolve, reject) => {
|
101
|
+
const timeout = setTimeout(() => {
|
102
|
+
reject(new Error('Voice connection timeout'));
|
103
|
+
}, 10000);
|
104
|
+
connection.on(voice_1.VoiceConnectionStatus.Ready, () => {
|
105
|
+
clearTimeout(timeout);
|
106
|
+
resolve(true);
|
107
|
+
});
|
108
|
+
connection.on(voice_1.VoiceConnectionStatus.Disconnected, () => {
|
109
|
+
clearTimeout(timeout);
|
110
|
+
reject(new Error('Failed to connect to voice channel'));
|
111
|
+
});
|
112
|
+
});
|
113
|
+
break;
|
114
|
+
}
|
115
|
+
case 'leaveVoiceChannel': {
|
116
|
+
const connection = (0, voice_1.getVoiceConnection)(guildId);
|
117
|
+
if (connection) {
|
118
|
+
connection.destroy();
|
119
|
+
}
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
default:
|
123
|
+
throw new Error(`The operation "${operation}" is not supported!`);
|
124
|
+
}
|
125
|
+
// Clean up: Destroy the client after operation is complete
|
126
|
+
client.destroy();
|
127
|
+
// Return success
|
128
|
+
return [this.helpers.returnJsonArray({ success: true })];
|
129
|
+
}
|
130
|
+
catch (error) {
|
131
|
+
// Clean up on error
|
132
|
+
client.destroy();
|
133
|
+
throw error;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
exports.DiscordAction = DiscordAction;
|
138
|
+
//# 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,2CAA+D;AAC/D,4CAM0B;AAC1B,qCAAmD;AACnD,8EAAuE;AAEvE,MAAa,aAAa;IAA1B;QACC,gBAAW,GAAyB;YACnC,WAAW,E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6IC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "n8n-nodes-discord-dnd",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.73",
|
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
|
}
|