Bot does not play any music, with no error message at all

it just shows application did not respond on discord, but no error message in terminal
export async function execute(interaction) {
const query = interaction.options.getString("query");
const songPath = `audio/${query}`;
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) return await interaction.reply("You need to be in a voice channel to play music!");
try{
const audioplayer = createAudioPlayer({
behaviors:{
noSubscriber:"pause",
},
});

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


const songResource = createAudioResource(songPath);
audioplayer.play(songResource);

vconnection.subscribe(audioplayer);
audioplayer.on(AudioPlayerStatus.Idle, async () =>{
await interaction.reply(`Song ended leaving the channel`);
audioplayer.stop();
vconnection.destroy();
});
} catch(error) {
console.log(error);
}
}
export async function execute(interaction) {
const query = interaction.options.getString("query");
const songPath = `audio/${query}`;
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) return await interaction.reply("You need to be in a voice channel to play music!");
try{
const audioplayer = createAudioPlayer({
behaviors:{
noSubscriber:"pause",
},
});

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


const songResource = createAudioResource(songPath);
audioplayer.play(songResource);

vconnection.subscribe(audioplayer);
audioplayer.on(AudioPlayerStatus.Idle, async () =>{
await interaction.reply(`Song ended leaving the channel`);
audioplayer.stop();
vconnection.destroy();
});
} catch(error) {
console.log(error);
}
}
audio source is an audio directory that has mp3 files
4 Replies
d.js toolkit
d.js toolkit3d 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!
NyR
NyR3d ago
Not sure if it's gonna help but try subscribing to the player first then play
Incorecc
IncoreccOP2d ago
That didn't work, but also there is another issue that is bugging me when I start my project npm run ..(basically running the bot) and I am not in a vc at that time, when I join the vc and use the command, it says you need to be in a vc. If I am already in the vc before running npm run .. this does not happen suppose the string has the valid filename, I have fixed my path to
const songPath = `../../audio/${query}`;
const songPath = `../../audio/${query}`;
cause that is how my project is structured. But why can't I debug anything, why was there no error even when createaudioresource gets the wrong path
d.js docs
d.js docsthis hour
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
Want results from more Discord servers?
Add your server