ytdl audioplayererror
Hi,
im trying to update my application so my bot connect to a voice channel, and put a sound on it.
I have this code :
// Function to start the music
async lancerMusique(message, numéroJeu) {
const vc = message.guild.channels.cache.find(
(channel) => channel.id === voiceChannel
);
const maZic = trouverMusiqueSelonJeu(numéroJeu);
if (!vc) {
return message.reply(
L'id du channel vocal : "${voiceChannel}" n'existe pas.
);
}
if (!maZic) {
return message.reply("La musique sélectionnée n'existe pas.");
}
try {
// Join the voice channel
const connection = joinVoiceChannel({
channelId: vc.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
// Stream the audio from YouTube URL with better configuration for ytdl-core
const stream = ytdl(maZic, {
filter: 'audioonly',
quality: 'highestaudio',
highWaterMark: 1 << 25 // Increase buffer size for smoother playback
});
// Create audio resource from the stream
const resource = createAudioResource(stream);
// Create the audio player
const player = createAudioPlayer();
// Play the audio
player.play(resource);
// Subscribe to the connection
connection.subscribe(player);
// Respond to the user
message.reply(La musique ${maZic} est jouée dans le vocal ! C'est la musique du __jeu ${numéroJeu}__.
);
// When the music stops, disconnect from the channel
player.on(AudioPlayerStatus.Idle, () => {
connection.destroy();
console.log("Déconnecté du channel vocal après la musique.");
});
} catch (error) {
console.error("Erreur lors de la lecture de la musique:", error);
message.reply("Il y a eu une erreur lors de la tentative de lecture de la musique.");
}
},
I have the last version for ytdl. However, i have this error that i don't know how to fix :
AudioPlayerError: Could not extract functions
Emitted 'error' event on AudioPlayer instance at:
Is someone knows how can i fix it ?
Thanks.4 Replies
- What are your intents?
GuildVoiceStates
is required to receive voice data!
- Show what dependencies you are using -- generateDependencyReport()
is exported from @discordjs/voice
.
- Try looking at common examples: https://github.com/discordjs/voice-examples.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPmy client :
const client = new Client({
intents: [
GatewayIntentBits.GuildVoiceStates,
],
});
node --version
v20.19.0
"discord.js": "^14.3.0",
We do not support TOS violations, which ytdl is
Mmmh so if i want to have a sound to display on a voice channel, i can't now ?