Почему зависает проигрывание музыки в моём боте Discord?
Почему зависает проигрывание музыки в моём боте Discord? Код, который запускает проигрывание музыки (interaction - команда):
async function col123(err, response, body) {
interaction.editReply('...')
if (err) interaction.editReply('Ошибка: ' + err)
const $ = cheerio.load(body);
const length = $("#unavailable-message").length;
if (length > 0) { // if the video is unavailable
interaction.editReply('Такого видео не существует!')
} else {
// do something when the video exists
console.log(link.split('/'))
if (!(link.split('/')[2] == "www.youtube.com" || link.split('/')[0] == "www.youtube.com" || link.split('/')[2] == "youtube.com" || link.split('/')[0] == "youtube.com")) {
interaction.editReply('Это ссылка не на YouTube')
return;
}
videos = true
if (!videos) {
interaction.editReply('Это не видео')
return;
} else {
console.log('Connecting')
const guild = await client.guilds.cache.get(interaction.guild.id)
const voiceChannel = await guild.channels.cache.get(interaction.member.voice.channelId)
const connection228 = await joinVoiceChannel({
channelId: voiceChannel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
})
console.log(connection228)
vidid = link.split('/')[3].split('')
console.log(vidid)
vidid.shift()
vidid.shift()
vidid.shift()
vidid.shift()
vidid.shift()
vidid.shift()
vidid.shift()
vidid.shift()
vidid = vidid.join('')
console.log(vidid)
video = await getVideoInfo(vidid)
console.log(video)
if (!video) {
interaction.editReply('Такого видео не существует, или же это не видео')
return;
}
const stream = await ytdl(link, { filter: 'audioonly' });
const resource = await createAudioResource(stream, { inputType: StreamType.Arbitrary });
const player = await createAudioPlayer();
player.play(resource);
connection228.subscribe(player);
interaction.editReply('Подключился')
connections[voiceChannel.id] = connection228
player.on(AudioPlayerStatus.Idle, () => connection228.destroy());
}
}
}
await request.get(link, (err, response, body) => {
if (!err) {
err = ""
}
col123(err, "", "")
});