fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.48k stars 793 forks source link

Invalid arg type error 'The "file" argument must be of type string' #581

Closed Ravenwulf closed 4 years ago

Ravenwulf commented 4 years ago

Hey, I can't find any solutions to this online so I figured i'd ask here.

When I run the below code in my discord.js bot, I receive the below error and I have no idea how to fix it or if the problem is even on my end.

My code works when a user types $queue <youtube url>

My Code

const ytdl = require('ytdl-core');
const streamOptions = {
    seek: 0,
    volume: 1
};
var musicUrls = [];
bot.on('message', async msg =>{
    if(msg.author.bot) return;
    if(msg.content.substring(0,PREFIX.length) === '$'){
        let args = msg.content.substring(PREFIX.length).split(" ");
        switch(args[0]){
            case 'queue':
                let url = args[1]
                let voiceChannel = msg.guild.channels.find(channel => channel.id === '582764408611143700');

                if(ytdl.validateURL(url)){
                    console.log("Valid URL!");
                    let flag = musicUrls.some(element => element === url);
                    if(!flag){
                        musicUrls.push(url);
                        if(voiceChannel != null){
                            if(voiceChannel.connection){
                                console.log("Connection exists.");
                                const embed = new Discord.RichEmbed();
                                embed.setAuthor(client.user.username, client.user.displayAvatarURL);
                                embed.setDescription("You've successfully added to the queue!");
                                msg.channel.send(embed);
                            }else{
                                try{
                                    const voiceConnection = await voiceChannel.join();
                                    await playSong(msg.channel, voiceConnection, voiceChannel);
                                }catch(ex){
                                    console.log(ex);
                                }
                            }
                        }
                    }
                }
            break;
            default:
            break;
        }
    }
});
async function playSong(messageChannel, voiceConnection, voiceChannel){
    const stream = ytdl(musicUrls[0], {filter : 'audioonly'});
    const dispatcher = voiceConnection.playStream(stream, streamOptions);

}

The Error

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
    at validateString (internal/validators.js:112:11)
    at normalizeSpawnArguments (child_process.js:398:3)
    at Object.spawn (child_process.js:534:16)
    at new FfmpegProcess (E:\Coding Stuff\DiscordBot\node_modules\prism-media\src\transcoders\ffmpeg\FfmpegProcess.js:14:33)
    at FfmpegTranscoder.transcode (E:\Coding Stuff\DiscordBot\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:34:18)
    at MediaTranscoder.transcode (E:\Coding Stuff\DiscordBot\node_modules\prism-media\src\transcoders\MediaTranscoder.js:27:31)
    at Prism.transcode (E:\Coding Stuff\DiscordBot\node_modules\prism-media\src\Prism.js:13:28)
    at AudioPlayer.playUnknownStream (E:\Coding Stuff\DiscordBot\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:97:35)
    at VoiceConnection.playStream (E:\Coding Stuff\DiscordBot\node_modules\discord.js\src\client\voice\VoiceConnection.js:478:24)
    at playSong (E:\Coding Stuff\DiscordBot\index.js:143:40) {

I understand what the error is trying to tell me but it seems to me that I am passing a string so...

fent commented 4 years ago

the stack trace shows the error is coming from prism-media. I tried looking at the source code from that line, but it looks like that file is no longer there

https://github.com/amishshah/prism-media/tree/master/src

likely you're using an older version of prism-media

Ravenwulf commented 4 years ago

So what do you suggest I do to fix it? I already installed the latest version of ytdl. Is there a way to easily get the new version of prism-media w/o risk of screwing something up?

fent commented 4 years ago

look at what depends on it that you have, and update that. it's probably discord.js. and then make sure it's on its latest version by checking with npm version prism-media

Ravenwulf commented 4 years ago

Well, I tried to do that and now i'm getting this error. Forgive me, I'm not used to this side of programming. I couldnt find any object declarations so im not sure why its telling me that Prism is not a constructor.

2020-02-29T06:49:18.362690+00:00 app[worker.1]: TypeError: Prism is not a constructor
2020-02-29T06:49:18.362692+00:00 app[worker.1]:     at new VoiceConnection (/app/node_modules/discord.js/src/client/voice/VoiceConnection.js:46:18)
2020-02-29T06:49:18.362693+00:00 app[worker.1]:     at /app/node_modules/discord.js/src/client/voice/ClientVoiceManager.js:63:22
2020-02-29T06:49:18.362693+00:00 app[worker.1]:     at new Promise (<anonymous>)
2020-02-29T06:49:18.362695+00:00 app[worker.1]:     at ClientVoiceManager.joinChannel (/app/node_modules/discord.js/src/client/voice/ClientVoiceManager.js:45:12)
2020-02-29T06:49:18.362695+00:00 app[worker.1]:     at VoiceChannel.join (/app/node_modules/discord.js/src/structures/VoiceChannel.js:130:30)
2020-02-29T06:49:18.362696+00:00 app[worker.1]:     at Client.<anonymous> (/app/index.js:124:80)
2020-02-29T06:49:18.362696+00:00 app[worker.1]:     at Client.emit (events.js:323:22)
2020-02-29T06:49:18.362697+00:00 app[worker.1]:     at MessageCreateHandler.handle (/app/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
2020-02-29T06:49:18.362736+00:00 app[worker.1]:     at WebSocketPacketManager.handle (/app/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
2020-02-29T06:49:18.362737+00:00 app[worker.1]:     at WebSocketConnection.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)

And seriously thanks for helping man, this isn't even really your problem but the fact that you were willing to help me is awfully humbling.

fent commented 4 years ago

the syntax for the new version of prism updated. look at the files in the stack trace that are yours. in this case, app/index.js