n8n-nodes-discord-dnd 0.1.73 → 0.1.75
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.
@@ -1,4 +1,4 @@
|
|
1
|
-
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from
|
1
|
+
import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
|
2
2
|
export declare class DiscordAction implements INodeType {
|
3
3
|
description: INodeTypeDescription;
|
4
4
|
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
|
@@ -4,115 +4,144 @@ exports.DiscordAction = void 0;
|
|
4
4
|
const discord_js_1 = require("discord.js");
|
5
5
|
const voice_1 = require("@discordjs/voice");
|
6
6
|
const client_1 = require("./client");
|
7
|
-
const DiscordIntentMapping_1 = require("../definitions/DiscordIntentMapping");
|
8
7
|
class DiscordAction {
|
9
8
|
constructor() {
|
10
9
|
this.description = {
|
11
|
-
displayName:
|
12
|
-
name:
|
13
|
-
icon:
|
14
|
-
group: [
|
10
|
+
displayName: "Discord Action",
|
11
|
+
name: "discordAction",
|
12
|
+
icon: "file:../assets/icon/discord.svg",
|
13
|
+
group: ["output"],
|
15
14
|
version: 1,
|
16
|
-
description:
|
15
|
+
description: "Perform Discord voice channel operations",
|
17
16
|
defaults: {
|
18
|
-
name:
|
17
|
+
name: "Discord Action",
|
19
18
|
},
|
20
|
-
inputs: [
|
21
|
-
outputs: [
|
19
|
+
inputs: ["main"],
|
20
|
+
outputs: ["main"],
|
22
21
|
credentials: [
|
23
22
|
{
|
24
|
-
name:
|
23
|
+
name: "discordApi",
|
25
24
|
required: true,
|
26
25
|
},
|
27
26
|
],
|
28
27
|
properties: [
|
29
28
|
{
|
30
|
-
displayName:
|
31
|
-
name:
|
32
|
-
type:
|
29
|
+
displayName: "Operation",
|
30
|
+
name: "operation",
|
31
|
+
type: "options",
|
33
32
|
options: [
|
34
33
|
{
|
35
|
-
name:
|
36
|
-
value:
|
37
|
-
description:
|
34
|
+
name: "Join Voice Channel",
|
35
|
+
value: "joinVoiceChannel",
|
36
|
+
description: "Join a voice channel",
|
38
37
|
},
|
39
38
|
{
|
40
|
-
name:
|
41
|
-
value:
|
42
|
-
description:
|
39
|
+
name: "Leave Voice Channel",
|
40
|
+
value: "leaveVoiceChannel",
|
41
|
+
description: "Leave the current voice channel",
|
43
42
|
},
|
44
43
|
],
|
45
|
-
default:
|
44
|
+
default: "joinVoiceChannel",
|
46
45
|
required: true,
|
47
46
|
},
|
48
47
|
{
|
49
|
-
displayName:
|
50
|
-
name:
|
51
|
-
type:
|
52
|
-
default:
|
48
|
+
displayName: "Guild ID",
|
49
|
+
name: "guildId",
|
50
|
+
type: "string",
|
51
|
+
default: "",
|
53
52
|
required: true,
|
54
|
-
description:
|
53
|
+
description: "The ID of the Discord server (guild)",
|
55
54
|
},
|
56
55
|
{
|
57
|
-
displayName:
|
58
|
-
name:
|
59
|
-
type:
|
60
|
-
default:
|
56
|
+
displayName: "Channel ID",
|
57
|
+
name: "channelId",
|
58
|
+
type: "string",
|
59
|
+
default: "",
|
61
60
|
displayOptions: {
|
62
61
|
show: {
|
63
|
-
operation: [
|
62
|
+
operation: ["joinVoiceChannel"],
|
64
63
|
},
|
65
64
|
},
|
66
65
|
required: true,
|
67
|
-
description:
|
66
|
+
description: "The ID of the voice channel to join",
|
68
67
|
},
|
69
68
|
],
|
70
69
|
};
|
71
70
|
}
|
72
71
|
async execute() {
|
73
|
-
const credentials = await this.getCredentials(
|
74
|
-
const operation = this.getNodeParameter(
|
75
|
-
const guildId = this.getNodeParameter(
|
72
|
+
const credentials = await this.getCredentials("discordApi");
|
73
|
+
const operation = this.getNodeParameter("operation", 0);
|
74
|
+
const guildId = this.getNodeParameter("guildId", 0);
|
75
|
+
const channelId = this.getNodeParameter("channelId", 0);
|
76
76
|
// Initialize Discord client with voice intents
|
77
|
-
const clientOptions =
|
77
|
+
const clientOptions = {
|
78
|
+
intents: [
|
79
|
+
discord_js_1.GatewayIntentBits.Guilds,
|
80
|
+
discord_js_1.GatewayIntentBits.GuildMessages,
|
81
|
+
discord_js_1.GatewayIntentBits.MessageContent,
|
82
|
+
discord_js_1.GatewayIntentBits.DirectMessages,
|
83
|
+
discord_js_1.GatewayIntentBits.GuildVoiceStates,
|
84
|
+
],
|
85
|
+
partials: [discord_js_1.Partials.Channel],
|
86
|
+
};
|
78
87
|
const client = await (0, client_1.initializeDiscordClient)(credentials.botToken, clientOptions);
|
79
88
|
try {
|
80
89
|
const guild = await client.guilds.fetch(guildId);
|
81
90
|
if (!guild) {
|
82
91
|
throw new Error(`Could not find guild with ID ${guildId}`);
|
83
92
|
}
|
93
|
+
const voiceChannel = (await guild.channels.fetch(channelId));
|
94
|
+
if (!voiceChannel || voiceChannel.type !== 2) {
|
95
|
+
// 2 = GUILD_VOICE
|
96
|
+
throw new Error("Channel is not a voice channel!");
|
97
|
+
}
|
84
98
|
switch (operation) {
|
85
|
-
case
|
86
|
-
|
87
|
-
const channel = await guild.channels.fetch(channelId);
|
88
|
-
if (!channel || !(channel instanceof discord_js_1.VoiceChannel)) {
|
99
|
+
case "joinVoiceChannel": {
|
100
|
+
if (!voiceChannel || !(voiceChannel instanceof discord_js_1.VoiceChannel)) {
|
89
101
|
throw new Error(`Channel ${channelId} is not a voice channel`);
|
90
102
|
}
|
103
|
+
// Check bot permissions
|
104
|
+
const permissions = voiceChannel.permissionsFor(client.user);
|
105
|
+
if (!(permissions === null || permissions === void 0 ? void 0 : permissions.has(discord_js_1.PermissionsBitField.Flags.Connect))) {
|
106
|
+
throw new Error("Bot does not have permission to join this voice channel");
|
107
|
+
}
|
108
|
+
if (!(permissions === null || permissions === void 0 ? void 0 : permissions.has(discord_js_1.PermissionsBitField.Flags.Speak))) {
|
109
|
+
throw new Error("Bot does not have permission to speak in this voice channel");
|
110
|
+
}
|
111
|
+
// Create connection
|
91
112
|
const connection = (0, voice_1.joinVoiceChannel)({
|
92
|
-
channelId
|
93
|
-
guildId
|
94
|
-
adapterCreator: guild
|
113
|
+
channelId,
|
114
|
+
guildId,
|
115
|
+
adapterCreator: voiceChannel.guild
|
116
|
+
.voiceAdapterCreator,
|
117
|
+
selfDeaf: false,
|
118
|
+
selfMute: false,
|
95
119
|
});
|
96
120
|
// Create an audio player to keep the connection alive
|
97
121
|
const player = (0, voice_1.createAudioPlayer)();
|
98
122
|
connection.subscribe(player);
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
123
|
+
try {
|
124
|
+
// Wait for the connection to be ready with a timeout
|
125
|
+
await Promise.race([
|
126
|
+
(0, voice_1.entersState)(connection, voice_1.VoiceConnectionStatus.Ready, 30000),
|
127
|
+
new Promise((_, reject) => {
|
128
|
+
connection.on(voice_1.VoiceConnectionStatus.Disconnected, () => {
|
129
|
+
reject(new Error("Voice connection was disconnected"));
|
130
|
+
});
|
131
|
+
connection.on("error", (error) => {
|
132
|
+
reject(error);
|
133
|
+
});
|
134
|
+
}),
|
135
|
+
]);
|
136
|
+
}
|
137
|
+
catch (error) {
|
138
|
+
// Clean up if connection fails
|
139
|
+
connection.destroy();
|
140
|
+
throw new Error(`Failed to join voice channel: ${(error === null || error === void 0 ? void 0 : error.message) || "Unknown error"}`);
|
141
|
+
}
|
113
142
|
break;
|
114
143
|
}
|
115
|
-
case
|
144
|
+
case "leaveVoiceChannel": {
|
116
145
|
const connection = (0, voice_1.getVoiceConnection)(guildId);
|
117
146
|
if (connection) {
|
118
147
|
connection.destroy();
|
@@ -124,8 +153,17 @@ class DiscordAction {
|
|
124
153
|
}
|
125
154
|
// Clean up: Destroy the client after operation is complete
|
126
155
|
client.destroy();
|
127
|
-
// Return success
|
128
|
-
return [
|
156
|
+
// Return success with additional details
|
157
|
+
return [
|
158
|
+
this.helpers.returnJsonArray({
|
159
|
+
success: true,
|
160
|
+
operation,
|
161
|
+
guildId,
|
162
|
+
channelId: operation === "joinVoiceChannel"
|
163
|
+
? this.getNodeParameter("channelId", 0)
|
164
|
+
: undefined,
|
165
|
+
}),
|
166
|
+
];
|
129
167
|
}
|
130
168
|
catch (error) {
|
131
169
|
// Clean up on error
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"DiscordAction.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordAction.node.ts"],"names":[],"mappings":";;;AAMA,
|
1
|
+
{"version":3,"file":"DiscordAction.node.js","sourceRoot":"","sources":["../../src/nodes/DiscordAction.node.ts"],"names":[],"mappings":";;;AAMA,2CAOoB;AACpB,4CAO0B;AAC1B,qCAAmD;AAGnD,MAAa,aAAa;IAA1B;QACE,gBAAW,GAAyB;YAClC,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;gBACR,IAAI,EAAE,gBAAgB;aACvB;YACD,MAAM,EAAE,CAAC,MAAM,CAAC;YAChB,OAAO,EAAE,CAAC,MAAM,CAAC;YACjB,WAAW,EAAE;gBACX;oBACE,IAAI,EAAE,YAAY;oBAClB,QAAQ,EAAE,IAAI;iBACf;aACF;YACD,UAAU,EAAE;gBACV;oBACE,WAAW,EAAE,WAAW;oBACxB,IAAI,EAAE,WAAW;oBACjB,IAAI,EAAE,SAAS;oBACf,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,oBAAoB;4BAC1B,KAAK,EAAE,kBAAkB;4BACzB,WAAW,EAAE,sBAAsB;yBACpC;wBACD;4BACE,IAAI,EAAE,qBAAqB;4BAC3B,KAAK,EAAE,mBAAmB;4BAC1B,WAAW,EAAE,iCAAiC;yBAC/C;qBACF;oBACD,OAAO,EAAE,kBAAkB;oBAC3B,QAAQ,EAAE,IAAI;iBACf;gBACD;oB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