#node.js #discord.js #bots #audio-player
#node.js #discord.js #боты #аудиоплеер
Вопрос:
У меня возникли проблемы с тем, чтобы заставить моего бота discord воспроизводить песни. Он может войти в голосовой канал и выполнить поиск песни, но когда он входит, он ничего не воспроизводит, я смотрю на состояние проигрывателя, и он выходит «буферизация».
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, AudioPlayerStatus, NoSubscriberBehavior } = require('@discordjs/voice'); const { Client, Intents, Interaction } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const ytdl = require('ytdl-core'); const yrS = require('yt-search'); async function vdSearch(cancion){ const vdE = await yrS(cancion); return vdE.videos.length gt; 0 ? vdE.videos[0] : null; } client.on('messageCreate', async(message) =gt;{ switch(args[0]){ case 'play': const vdRepro = await vdSearch(args[1]); if(!vdRepro){ message.channel.send("No se ha encontrado esa cancion"); }else{ message.channel.send("Reproduciendo: " vdRepro.title); } //CONEXION const stream = ytdl(vdRepro.url, { filter:'audioonly' }); const connection = joinVoiceChannel({ channelId: message.member.voice.channel.id, guildId: message.guild.id, adapterCreator: message.guild.voiceAdapterCreator }) var resource = createAudioResource(stream, {inputType:StreamType.Arbitrary,}); const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause, }, }); player.play(resource); connection.subscribe(player); console.log(player.state); break; } })
Кто-нибудь знает, как я мог бы это решить? Спасибо, что нашли время прочитать