not playing

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

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

const player = createAudioPlayer();
const resource = createAudioResource(
path.join(__dirname, "./music/audio.mp3")
);

player.play(resource);
connection.subscribe(player);

player.on("error", (error) => {
console.error(`Audio player error: ${error.message}`);
});
const voiceChannel = interaction.member?.voice.channel;

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

const player = createAudioPlayer();
const resource = createAudioResource(
path.join(__dirname, "./music/audio.mp3")
);

player.play(resource);
connection.subscribe(player);

player.on("error", (error) => {
console.error(`Audio player error: ${error.message}`);
});
the bot joins, no errors, yet no music playin
2 Replies
d.js toolkit
d.js toolkit3w ago
- 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!
d.js docs
d.js docs3w ago
To debug your voice connection and player: - Use debug: true when creating your VoiceConnection and AudioPlayer - Add an event listener to the <VoiceConnection> and the <AudioPlayer>:
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
- Add an error listener to the stream you are passing to the resource:
<Stream>.on('error', console.error)
<Stream>.on('error', console.error)
Note: The <> represents classes that need to be adapted to their respective name in your code

Did you find this page helpful?