I want download a audio file via ytdl-core and play it, but when i try to play it with connection.playFile() i get the following error:
TypeError [ERR_INVALID_ARG_TYPE]: The “file” argument must be of type string. Received type object
TypeError [ERR_INVALID_ARG_TYPE]: The “file” argument must be of type string. Received type object
var Module=typeof Module!==“undefined”?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module[“arguments”]=;Module[“thisProgram”]="./this.program";Module[“quit”]=function(status,toThrow){throw toThrow};Module[“preRun”]=;Module[“postRun”]=;var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window===“object”;ENVIRONMENT_IS_WORKER=typeof importScripts===“function”;ENVIRONMENT_HAS_NODE=typeof process===“object”&&typeof process.versions===“object”&&typeof process.versions.node===“string”;ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile
abort(TypeError [ERR_INVALID_ARG_TYPE]: The “file” argument must be of type string. Received type object). Build with -s ASSERTIONS=1 for more info.strong text
This is the code i’ using:
async run(args: string[], msgObject: Discord.Message, client: Discord.Client): Promise<void> {
const url = args[0];
var stream = ytdl(url);
const streamOptions = { seek: 0, volume: 1 };
try {
await stream.pipe(fs.createWriteStream('tmp_buf_audio.mp3'))
msgObject.delete();
msgObject.member.voiceChannel.join()
.then(connection =>{
msgObject.reply("Succesfully joined")
connection.playFile('./tmp_buf_audio', streamOptions)
.on("end", () => {
connection.channel.leave();
})
})
}
catch {
msgObject.channel.send("You have to be in a Voicechannel to use this command");
}