gpt4 book ai didi

javascript - Discord JS 音乐机器人的问题

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:10 25 4
gpt4 key购买 nike

我正在使用 JS 创建一个 Discord 机器人,为其提供管理、自动 Angular 色等。我刚刚进入它的音乐部分,但我不太明白出了什么问题。

我相信我已经正确安装了 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.

这是我调用播放的代码:

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.效果就像一个魅力!

最佳答案

您尝试播放message,消息它是一个不和谐的集合。您需要使用 play args[number]

更换

if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection) {
play(connection, message);
});

if (!message.guild.voiceConnection) message.member.voiceChannel.join().then(function(connection) {
play(connection, args[1]);
});

关于javascript - Discord JS 音乐机器人的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59980583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com