У меня при запуске музыки через моего бота проходит пару минут и пишет ошибку
22.03.2024, 14:56. Показов 915. Ответов 2
Вот код с файла index.js:
| JavaScript | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| import { Client, GatewayIntentBits, REST } from 'discord.js';
import { commands, handleCommandInteraction } from './commands.js';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
],
});
const rest = new REST({ version: '10' }).setToken("***");
client.once('ready', async () => {
try {
console.log('Начало обновления глобальных команд приложения (/).');
await rest.put(
`/applications/${client.user.id}/commands`,
{ body: commands }
);
console.log('Глобальные команды приложения (/) успешно обновлены.');
} catch (error) {
console.error('Ошибка при обновлении глобальных команд:', error);
}
});
client.on('interactionCreate', async (interaction) => {
try {
if (!interaction.isCommand()) return;
const voiceChannel = interaction.member?.voice.channel;
if (!voiceChannel) {
await interaction.reply('Вы должны находиться в голосовом канале, чтобы использовать эту команду.');
return;
}
const permissions = voiceChannel.permissionsFor(interaction.client.user);
if (!permissions || !permissions.has('CONNECT') || !permissions.has('SPEAK')) {
await interaction.reply('Мне нужны разрешения для подключения и общения в вашем голосовом канале!');
return;
}
await handleCommandInteraction(interaction); // Обработка команды
} catch (error) {
console.error('Ошибка при обработке взаимодействия:', error);
await interaction.reply('Произошла ошибка при обработке вашего запроса.');
}
});
client.login("***"); |
|
А вот код с файла commands.js:
| JavaScript | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
| import { getVoiceConnection, joinVoiceChannel, createAudioPlayer, createAudioResource } from '@discordjs/voice';
import ytdl from 'ytdl-core';
const commands = [
{
name: 'skip',
description: 'Skip the currently playing song',
},
{
name: 'leave',
description: 'Leave your channel!',
},
{
name: 'play',
description: 'Play music from a URL',
options: [
{
name: 'url',
type: 3,
description: 'URL of the audio to play',
required: true,
},
],
},
{
name: 'pause',
description: 'Pause the music',
},
{
name: 'resume',
description: 'Resume music playback',
},
{
name: 'stop',
description: 'Stop the music playback',
},
{
name: 'queue',
description: 'Add a song to the queue',
options: [
{
name: 'url',
type: 3,
description: 'URL of the audio to add to the queue',
required: true,
},
],
},
];
const handleLeaveCommand = (interaction) => {
const currentConnection = getVoiceConnection(interaction.guildId);
if (currentConnection) {
currentConnection.destroy();
interaction.reply('Left the voice channel.');
} else {
interaction.reply('The bot is not in the current channel');
}
};
const handlePlayCommand = async (interaction, options) => {
try {
if (interaction.member && interaction.member.voice.channel) {
const audioUrl = options.getString('url');
if (ytdl.validateURL(audioUrl)) {
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
const stream = ytdl(audioUrl, { filter: 'audioonly' });
const player = createAudioPlayer();
const resource = createAudioResource(stream);
player.play(resource);
connection.subscribe(player);
const videoInfo = await ytdl.getInfo(audioUrl);
const audioTitle = videoInfo.videoDetails.title;
interaction.reply(`Joined and now playing in ${interaction.member.voice.channel.name}. Now playing: ${audioTitle}`);
} else {
interaction.reply('Invalid or unsupported audio URL.');
}
} else {
interaction.reply('You must be in a voice channel to use this command.');
}
} catch (error) {
console.error(error);
interaction.reply('An error occurred while processing the play command.');
}
};
const handleResumeCommand = (interaction) => {
const connection = getVoiceConnection(interaction.guildId);
if (connection) {
const player = connection.state.subscription.player;
if (player) {
player.unpause();
interaction.reply('Music playback resumed.');
} else {
interaction.reply('No music is currently paused.');
}
} else {
interaction.reply('Bot is not in a voice channel.');
}
};
const handleStopCommand = (interaction) => {
const connection = getVoiceConnection(interaction.guildId);
if (connection) {
const player = connection.state.subscription.player;
if (player) {
player.stop(); // Method to stop playback
interaction.reply('Music playback stopped.');
} else {
interaction.reply('No music is currently playing.');
}
} else {
interaction.reply('Bot is not in a voice channel.');
}
};
const handleQueueCommand = async (interaction, options) => {
try {
if (interaction.member && interaction.member.voice.channel) {
const audioUrl = options.getString('url');
if (ytdl.validateURL(audioUrl)) {
const connection = getVoiceConnection(interaction.member.voice.guild.id);
if (connection) {
const stream = ytdl(audioUrl, { filter: 'audioonly' });
const player = connection.state.subscription.player;
if (!player.queue) {
player.queue = [];
}
const resource = createAudioResource(stream);
player.queue.push(resource);
const videoInfo = await ytdl.getInfo(audioUrl);
const audioTitle = videoInfo.videoDetails.title;
interaction.reply({
content: `Added to queue: ${audioTitle}`,
ephemeral: false,
});
} else {
interaction.reply('Bot is not in a voice channel.');
}
} else {
interaction.reply('Invalid or unsupported audio URL.');
}
} else {
interaction.reply('You must be in a voice channel to use this command.');
}
} catch (error) {
console.error(error);
interaction.reply('An error occurred while processing the queue command.');
}
};
const handleSkipCommand = async (interaction) => {
try {
const connection = getVoiceConnection(interaction.member.voice.guild.id);
if (connection) {
const player = connection.state.subscription.player;
if (player) {
player.stop(); // Skip the currently playing song
// Check if there are items in the queue
if (player.queue && player.queue.length > 0) {
const nextResource = player.queue.shift(); // Get and remove the first item from the queue
player.play(nextResource); // Play the next item in the queue
}
interaction.reply('Skipped the currently playing song.');
} else {
interaction.reply('No music is currently playing.');
}
} else {
interaction.reply('Bot is not in a voice channel.');
}
} catch (error) {
console.error(error);
interaction.reply('An error occurred while processing the skip command.');
}
};
const handlePauseCommand = (interaction) => {
const connection = getVoiceConnection(interaction.guildId);
if (connection) {
const player = connection.state.subscription.player;
if (player) {
player.pause(); // Method to pause playback
interaction.reply('Music playback paused.');
} else {
interaction.reply('No music is currently playing.');
}
} else {
interaction.reply('Bot is not in a voice channel.');
}
};
const handleCommandInteraction = async (interaction) => {
try {
const { commandName, options } = interaction;
if (commandName === 'leave') {
handleLeaveCommand(interaction);
} else if (commandName === 'play') {
await handlePlayCommand(interaction, options);
} else if (commandName === 'resume') {
handleResumeCommand(interaction);
} else if (commandName === 'stop') {
handleStopCommand(interaction);
} else if (commandName === 'queue') {
await handleQueueCommand(interaction, options);
} else if (commandName === 'skip') {
await handleSkipCommand(interaction);
} else if (commandName === 'pause') {
handlePauseCommand(interaction);
} else {
interaction.reply('Unknown command');
}
} catch (error) {
console.error(error);
interaction.reply('An error occurred while processing the command.');
}
};
export {
commands,
handleCommandInteraction,
}; |
|
Вот первая ошибка когда запускается музыка на одном сервере в Discord:
| Code | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
| throw er; // Unhandled 'error' event
^
AudioPlayerError: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7)
Emitted 'error' event on AudioPlayer instance at:
at OggDemuxer.onStreamError (file:///D:/%D0%B1%D0%BE%D1%82%D1%8D/v2/node_modules/@discordjs/voice/dist/index.mjs:1069:14)
at Object.onceWrapper (node:events:629:26)
at OggDemuxer.emit (node:events:526:35)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
resource: <ref *3> AudioResource {
playStream: OggDemuxer {
_readableState: ReadableState {
highWaterMark: 16,
buffer: BufferList {
head: { data: [Buffer [Uint8Array]], next: [Object] },
tail: { data: [Buffer [Uint8Array]], next: null },
length: 314
},
length: 314,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 1866769,
[Symbol(kErroredValue)]: Error: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7) {
code: 'ECONNRESET'
}
},
_events: [Object: null prototype] {
prefinish: [Function: prefinish],
close: [
[Function (anonymous)],
[Function: onclose],
[Function (anonymous)],
[Function: onclose]
],
end: [ [Function: onend], [Function: onend] ],
finish: [ [Function: onfinish], [Function: onfinish] ],
error: [
[Function: onerror],
[Function: onError],
[Function: onerror]
]
},
_eventsCount: 5,
_maxListeners: undefined,
_writableState: WritableState {
highWaterMark: 16384,
length: 73914,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 73914,
bufferedIndex: 0,
pendingcb: 1,
[Symbol(kState)]: 170707444,
[Symbol(kBufferedValue)]: null,
[Symbol(kErroredValue)]: Error: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7) {
code: 'ECONNRESET'
}
},
allowHalfOpen: true,
_remainder: null,
_head: null,
_bitstream: null,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: [Function: bound onwrite]
},
edges: [
<ref *1> {
type: 'ffmpeg ogg',
to: Node {
edges: [ [Object], [Object], [Object] ],
type: 'ogg/opus'
},
cost: 2,
transformer: [Function: transformer],
from: Node { edges: [ [Object], [Circular *1] ], type: 'arbitrary' }
},
<ref *2> {
type: 'ogg/opus demuxer',
to: Node { edges: [ [Object] ], type: 'opus' },
cost: 1,
transformer: [Function: transformer],
from: Node {
edges: [ [Circular *2], [Object], [Object] ],
type: 'ogg/opus'
}
}
],
metadata: null,
volume: undefined,
encoder: undefined,
audioPlayer: <ref *4> AudioPlayer {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_state: {
status: 'playing',
missedFrames: 0,
playbackDuration: 99720,
resource: [Circular *3],
onStreamError: [Function: onStreamError]
},
subscribers: [
PlayerSubscription {
connection: VoiceConnection {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
rejoinAttempts: 0,
_state: [Object],
joinConfig: [Object],
packets: [Object],
receiver: [VoiceReceiver],
debug: null,
onNetworkingClose: [Function: bound onNetworkingClose],
onNetworkingStateChange: [Function: bound onNetworkingStateChange],
onNetworkingError: [Function: bound onNetworkingError],
onNetworkingDebug: [Function: bound onNetworkingDebug],
[Symbol(kCapture)]: false
},
player: [Circular *4]
}
],
behaviors: { noSubscriber: 'pause', maxMissedFrames: 5 },
debug: [Function (anonymous)],
[Symbol(kCapture)]: false
},
playbackDuration: 99720,
started: true,
silencePaddingFrames: 5,
silenceRemaining: -1
}
} |
|
А вот вторая ошибка когда на двух серверах запускается музыка в Discord:
| Code | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
| node:events:492
throw er; // Unhandled 'error' event
^
AudioPlayerError: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7)
Emitted 'error' event on AudioPlayer instance at:
at OggDemuxer.onStreamError (file:///D:/%D0%B1%D0%BE%D1%82%D1%8D/v2/node_modules/@discordjs/voice/dist/index.mjs:1069:14)
at Object.onceWrapper (node:events:629:26)
at OggDemuxer.emit (node:events:526:35)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
resource: <ref *3> AudioResource {
playStream: OggDemuxer {
_readableState: ReadableState {
highWaterMark: 16,
buffer: BufferList {
head: { data: [Buffer [Uint8Array]], next: [Object] },
tail: { data: [Buffer [Uint8Array]], next: null },
length: 313
},
length: 313,
pipes: [],
awaitDrainWriters: null,
[Symbol(kState)]: 1866769,
[Symbol(kErroredValue)]: Error: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7) {
code: 'ECONNRESET'
}
},
_events: [Object: null prototype] {
prefinish: [Function: prefinish],
close: [
[Function (anonymous)],
[Function: onclose],
[Function (anonymous)],
[Function: onclose]
],
end: [ [Function: onend], [Function: onend] ],
finish: [ [Function: onfinish], [Function: onfinish] ],
error: [
[Function: onerror],
[Function: onError],
[Function: onerror]
]
},
_eventsCount: 5,
_maxListeners: undefined,
_writableState: WritableState {
highWaterMark: 16384,
length: 66898,
corked: 0,
onwrite: [Function: bound onwrite],
writelen: 66898,
bufferedIndex: 0,
pendingcb: 1,
[Symbol(kState)]: 170707444,
[Symbol(kBufferedValue)]: null,
[Symbol(kErroredValue)]: Error: aborted
at connResetException (node:internal/errors:787:14)
at TLSSocket.socketCloseListener (node:_http_client:455:19)
at TLSSocket.emit (node:events:526:35)
at node:net:337:12
at TCP.done (node:_tls_wrap:657:7) {
code: 'ECONNRESET'
}
},
allowHalfOpen: true,
_remainder: null,
_head: null,
_bitstream: null,
[Symbol(kCapture)]: false,
[Symbol(kCallback)]: [Function: bound onwrite]
},
edges: [
<ref *1> {
type: 'ffmpeg ogg',
to: Node {
edges: [ [Object], [Object], [Object] ],
type: 'ogg/opus'
},
cost: 2,
transformer: [Function: transformer],
from: Node { edges: [ [Object], [Circular *1] ], type: 'arbitrary' }
},
<ref *2> {
type: 'ogg/opus demuxer',
to: Node { edges: [ [Object] ], type: 'opus' },
cost: 1,
transformer: [Function: transformer],
from: Node {
edges: [ [Circular *2], [Object], [Object] ],
type: 'ogg/opus'
}
}
],
metadata: null,
volume: undefined,
encoder: undefined,
audioPlayer: <ref *4> AudioPlayer {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_state: {
status: 'playing',
missedFrames: 0,
playbackDuration: 57740,
resource: [Circular *3],
onStreamError: [Function: onStreamError]
},
subscribers: [
PlayerSubscription {
connection: VoiceConnection {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
rejoinAttempts: 0,
_state: [Object],
joinConfig: [Object],
packets: [Object],
receiver: [VoiceReceiver],
debug: null,
onNetworkingClose: [Function: bound onNetworkingClose],
onNetworkingStateChange: [Function: bound onNetworkingStateChange],
onNetworkingError: [Function: bound onNetworkingError],
onNetworkingDebug: [Function: bound onNetworkingDebug],
[Symbol(kCapture)]: false
},
player: [Circular *4]
}
],
behaviors: { noSubscriber: 'pause', maxMissedFrames: 5 },
debug: [Function (anonymous)],
[Symbol(kCapture)]: false
},
playbackDuration: 57740,
started: true,
silencePaddingFrames: 5,
silenceRemaining: -1
}
} |
|
0
|