'Discord js Voice | How to use AudioResource
I'm trying to create an AudioResource
according to the documentation, but I don't know what to fill in edges and streams. I only have yt(youtube-url)
from ytdl-core
. Please advise what information is required. I try create Audio Resource via new Voice.AudioResource
on way documentation. I know about createAudioResource
, but is there any possibility to do it differently?
client.on('messageCreate', (message) => {
if(message.content == '!test'){
const VoiceConnection = new Voice.VoiceConnection({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
selfDeaf: true,
}, {
adapterCreator: message.guild.voiceAdapterCreator,
debug: true
})
VoiceConnection.rejoin()
const Player = new Voice.AudioPlayer()
const Resource = new Voice.AudioResource([], [yt(youtube-url)]) // error
VoiceConnection.subscribe(Player)
Player.play(Resource)
}
})
Solution 1:[1]
createAudioPlayer isn't the most stable audio player but it is the only one fully supported by the Discord.js Developers at this time. It should be a good idea using the way they support. Take some minutes to read this document it is very important.
I think you want something like this:
audioPlayer.play(createAudioResource(stream))
I did not test this code but I think it works:
const { joinVoiceChannel } = require('@discordjs/voice');
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
const { createAudioPlayer } = require('@discordjs/voice');
const player = createAudioPlayer();
const songURL= 'https://www.youtube.com/watch?v=Ak5oJcXSnQw'
const stream = ytdl(songURL, {filter: 'audioonly'});
player.play(createAudioResource(stream));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Fernando Filipe |