Bot joining but not playing

const Discord = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');


module.exports = {
name: 'audio',


execute: async function(message, client, args, user, member) {
try{

const voiceChannel = message.member.voice?.channel;

if (!voiceChannel) {
return message.reply('Entra a un canal de voz primero.');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});

const player = createAudioPlayer();

const audio = createAudioResource('./audios/audio1.mp3', {
metadata: {
title: 'Audio1',
},
});

if(connection) {
message.reply(`Conectado al canal de voz <#${voiceChannel.id}>`)
player.play(audio)
console.log("Playing")
}


if(connection) {
setTimeout(() => connection.destroy(), 5_000);
setTimeout(() => player.stop(), 5_000);
}

} catch (error) {
console.error(error);
return false;
}
}

}
const Discord = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');


module.exports = {
name: 'audio',


execute: async function(message, client, args, user, member) {
try{

const voiceChannel = message.member.voice?.channel;

if (!voiceChannel) {
return message.reply('Entra a un canal de voz primero.');
}

const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
});

const player = createAudioPlayer();

const audio = createAudioResource('./audios/audio1.mp3', {
metadata: {
title: 'Audio1',
},
});

if(connection) {
message.reply(`Conectado al canal de voz <#${voiceChannel.id}>`)
player.play(audio)
console.log("Playing")
}


if(connection) {
setTimeout(() => connection.destroy(), 5_000);
setTimeout(() => player.stop(), 5_000);
}

} catch (error) {
console.error(error);
return false;
}
}

}
The bot join the channel but does not play the audio, there is not errors.
4 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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 OP
duck
duck15mo ago
you'll need to use <VoiceConnection>.subscribe() for the connection to know which player to play audio from if you still have issues playing audio, consider resolving an absolute path for your audio resource
d.js docs
d.js docs15mo ago
guide Library: Voice Connections - Cheat sheet > Playing audio read more
hugof5392
hugof5392OP15mo ago
it worked thx
Want results from more Discord servers?
Add your server