Im new to programing a discord bot, im more to the web developing enviroment, im trying to create by myself a play command song (only with one link) to try if the first join is working and actually play the song.
(Discord.js v14)
Unfortunately i was having a problem with FFMPEG. This my actual module for the play.js command, where all the problem is happening.
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const ytdl = require('ytdl-core');
module.exports = {
devOnly: true,
name: 'play',
description: 'Start to play a song!',
// options: Object[],
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const voiceChannel = interaction.member.voice.channel;
if (!voiceChannel) {
return interaction.reply('You must be in a voice channel to use this command.');
}
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
const stream = ytdl('URL_HERE', { filter: 'audioonly' });
const resource = createAudioResource(stream);
const player = createAudioPlayer();
connection.subscribe(player);
player.play(resource);
interaction.reply({
content: `Playing Song`,
// ephemeral: true,
});
}
}
The first error i was receving was 'Error: FFmpeg/avconv not found!', i tried to install it with some guides online. after couple of tries i get it right and the command 'ffmpeg -version' returns.
After that i tought it was workikng, but when i started my project, i receved the same error,. I tried to look up for a solution and i tried to get the process.env.PATH to see but i dont understand if its right or not.
After i removed the console.log(process.env.PATH), i get no errors in the terminal, but it will stil not play the song.
try specifying stream type. (
StreamTypeis including in @discordjs/voice)Old answer: Try
npm i tweetnacl ffmpeg-static @discordjs/opus. Discord.js v14 Voice can play with ffmpeg-static