【发布时间】:2020-05-15 17:56:21
【问题描述】:
我正在使用 JS 创建一个 Discord 机器人,为其提供管理、自动角色等。我刚刚进入它的音乐部分,但我不太明白哪里出了问题。
我相信我已经正确安装了 FFmpeg,因为我可以从终端中访问它。我还使用 npm 将 ytdl-core 和 opusscript 引入我的程序中。
这应该做的是让机器人加入聊天,然后播放 Youtube 链接。目前,我没有错误检查第二个参数,因为我只是想让它最初工作。我已经实现了几个不同的 .toString() 和 String() 实例,但是它总是给出下面列出的相同错误。
。程序仍然抛出这个错误:
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
C:\Users\Thresio's PC\Desktop\Discord Bot\node_modules\opusscript\build\opusscript_native_wasm.js:8
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&&!ENVIRONM
ENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var
scriptDirectory="";function locateFile(path){i
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.
这是我调用 play 的代码:
case 'play':
function play(connection, message){
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: 'audioonly'}));
server.queue.shift();
server.dispatcher.on('end', function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
})
}
if(!args[1]){
message.channel.send('You need to provide a link!');
return;
}
if(!message.member.voiceChannel){
message.channel.send('You must be in a voice channel to play music!');
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection){
play(connection, message);
})
break;
如果有人能提供帮助,我将不胜感激。
编辑:不幸的是,我从未弄清楚我的主要问题,但我现在找到了有效的代码(不像我的:/)。 对于其他遇到此问题的人,我建议使用代码found here. 像魅力一样工作!
【问题讨论】:
-
我现在也尝试了这个问题的解决方案:stackoverflow.com/questions/50571184/… 并且仍然抛出上面相同的错误。
标签: javascript node.js ffmpeg bots discord.js