Music bot autopause

Info: I am running this locally using node index.js. I have given the bot admin permission. I have added the GuildVoiceStates to the GatewayIntentBits. I have checked all 3 of the Privileged Gateway Intents found in the discord portal.
Dependencies: {
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.0",
"discord-player": "^6.6.5",
"discord.js": "^14.13.0",
"ffmpeg-static": "^5.2.0",
}
Dependencies: {
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.0",
"discord-player": "^6.6.5",
"discord.js": "^14.13.0",
"ffmpeg-static": "^5.2.0",
}
node -v - v18.12.0 npm -v - 8.19.2 Problem I am trying to get this bot to play music from a local file in the same folder as the /play command. The bot joins the channel, then the state changes to playing => autopaused => playing => idle. I have been trying for weeks, I looked through the discord group and added the GuildVoiceStates intent and even tried downloading and setting up ffmpeg manually (after I have already downlaoded ffmpeg-static using npm) using this youtube video: https://www.youtube.com/watch?v=SW-iKrT_nJs . The ffmepg command did not work, so I am not certain if this is why I am struggling, or if it is unrelated.
Crawl
YouTube
HOW TO "INSTALL" FFMPEG ON WINDOWS
Ever wanted to know how a core developer of DISCORD.JS uses his own library? I don't really care what you think, but if you want to leave feedback do so in the comments below. If there's anything wrong with anything I said and you actually picked up on it, correct me in the comments below and I may or may not respond with an angry comment. Pa...
2 Replies
d.js toolkit
d.js toolkit13mo 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
Leizest
LeizestOP13mo ago
Code:
const { SlashCommandBuilder } = require("@discordjs/builders");
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, VoiceConnectionStatus } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Loads songs from local"),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply("You need to be in a voice channel to use this command.");
}

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

connection.connection.on('error', error => {
console.error('Connection Error:', error);
});

console.log("Audio file path:", './drumeo-play-along-with-metronome.mp3');

const resource = createAudioResource('./drumeo-play-along-with-metronome.mp3', {
inlineVolume: true
});
console.log("Audio resource created:", resource);


resource.volume.setVolume(0.5);

player.play(resource);

player.on('stateChange', (oldState, newState) => {
console.log('currrent state: ', player.state);
});

player.on('error', error => {
console.error('Error:', error);
});


player.on(VoiceConnectionStatus.Disconnected, () => {
connection.destroy();
});

interaction.reply('Playing local audio in the voice channel.');
}
};
const { SlashCommandBuilder } = require("@discordjs/builders");
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType, VoiceConnectionStatus } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName("play")
.setDescription("Loads songs from local"),
async execute(interaction) {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply("You need to be in a voice channel to use this command.");
}

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

connection.connection.on('error', error => {
console.error('Connection Error:', error);
});

console.log("Audio file path:", './drumeo-play-along-with-metronome.mp3');

const resource = createAudioResource('./drumeo-play-along-with-metronome.mp3', {
inlineVolume: true
});
console.log("Audio resource created:", resource);


resource.volume.setVolume(0.5);

player.play(resource);

player.on('stateChange', (oldState, newState) => {
console.log('currrent state: ', player.state);
});

player.on('error', error => {
console.error('Error:', error);
});


player.on(VoiceConnectionStatus.Disconnected, () => {
connection.destroy();
});

interaction.reply('Playing local audio in the voice channel.');
}
};
Thank you! That fixed it. Didn't realize the file path worked that way.
Want results from more Discord servers?
Add your server