n8n-nodes-discord-dnd 0.1.74 → 0.1.76
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,103 +4,120 @@ 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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
//
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
}
|
96
|
-
if (!
|
97
|
-
|
98
|
-
|
99
|
+
case "joinVoiceChannel": {
|
100
|
+
// if (!voiceChannel || !(voiceChannel instanceof VoiceChannel)) {
|
101
|
+
// throw new Error(`Channel ${channelId} is not a voice channel`);
|
102
|
+
// }
|
103
|
+
// // Check bot permissions
|
104
|
+
// const permissions = voiceChannel.permissionsFor(client.user!);
|
105
|
+
// if (!permissions?.has(PermissionsBitField.Flags.Connect)) {
|
106
|
+
// throw new Error(
|
107
|
+
// "Bot does not have permission to join this voice channel"
|
108
|
+
// );
|
109
|
+
// }
|
110
|
+
// if (!permissions?.has(PermissionsBitField.Flags.Speak)) {
|
111
|
+
// throw new Error(
|
112
|
+
// "Bot does not have permission to speak in this voice channel"
|
113
|
+
// );
|
114
|
+
// }
|
99
115
|
// Create connection
|
100
116
|
const connection = (0, voice_1.joinVoiceChannel)({
|
101
|
-
channelId
|
102
|
-
guildId
|
103
|
-
adapterCreator: guild
|
117
|
+
channelId,
|
118
|
+
guildId,
|
119
|
+
adapterCreator: voiceChannel.guild
|
120
|
+
.voiceAdapterCreator,
|
104
121
|
selfDeaf: false,
|
105
122
|
selfMute: false,
|
106
123
|
});
|
@@ -113,9 +130,9 @@ class DiscordAction {
|
|
113
130
|
(0, voice_1.entersState)(connection, voice_1.VoiceConnectionStatus.Ready, 30000),
|
114
131
|
new Promise((_, reject) => {
|
115
132
|
connection.on(voice_1.VoiceConnectionStatus.Disconnected, () => {
|
116
|
-
reject(new Error(
|
133
|
+
reject(new Error("Voice connection was disconnected"));
|
117
134
|
});
|
118
|
-
connection.on(
|
135
|
+
connection.on("error", (error) => {
|
119
136
|
reject(error);
|
120
137
|
});
|
121
138
|
}),
|
@@ -124,11 +141,11 @@ class DiscordAction {
|
|
124
141
|
catch (error) {
|
125
142
|
// Clean up if connection fails
|
126
143
|
connection.destroy();
|
127
|
-
throw new Error(`Failed to join voice channel: ${(error === null || error === void 0 ? void 0 : error.message) ||
|
144
|
+
throw new Error(`Failed to join voice channel: ${(error === null || error === void 0 ? void 0 : error.message) || "Unknown error"}`);
|
128
145
|
}
|
129
146
|
break;
|
130
147
|
}
|
131
|
-
case
|
148
|
+
case "leaveVoiceChannel": {
|
132
149
|
const connection = (0, voice_1.getVoiceConnection)(guildId);
|
133
150
|
if (connection) {
|
134
151
|
connection.destroy();
|
@@ -141,12 +158,16 @@ class DiscordAction {
|
|
141
158
|
// Clean up: Destroy the client after operation is complete
|
142
159
|
client.destroy();
|
143
160
|
// Return success with additional details
|
144
|
-
return [
|
161
|
+
return [
|
162
|
+
this.helpers.returnJsonArray({
|
145
163
|
success: true,
|
146
164
|
operation,
|
147
165
|
guildId,
|
148
|
-
channelId: operation ===
|
149
|
-
|
166
|
+
channelId: operation === "joinVoiceChannel"
|
167
|
+
? this.getNodeParameter("channelId", 0)
|
168
|
+
: undefined,
|
169
|
+
}),
|
170
|
+
];
|
150
171
|
}
|
151
172
|
catch (error) {
|
152
173
|
// 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;oBACE,WAAW,EAAE,UAAU;oBACvB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,EAAE;oBACX,QAAQ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