【问题标题】:Issues with Discord JS Music BotDiscord JS 音乐机器人的问题
【发布时间】: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. 像魅力一样工作!

【问题讨论】:

标签: javascript node.js ffmpeg bots discord.js


【解决方案1】:

我实际上能够修复您的代码。您需要安装这些模块:

npm install discord.js ffmpeg fluent-ffmpeg @discordjs/opus ytdl-core --save

然后像这样运行脚本:

NODE_TLS_REJECT_UNAUTHORIZED='0' node bot.js

【讨论】:

    【解决方案2】:

    你试试玩 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]);
    });
    

    【讨论】:

    • 与上面列出的相同,在问题的第一个“代码”部分。
    • if(server.queue[0]){ play(connection, message);也改一下
    • 抱歉,回复延迟。我在那里和其他任何地方都改变了它,但从未弄清楚我的问题。我现在已经删除了我的播放代码,并在这里使用了代码 link 与我的不同,它确实有效。无论如何感谢您的帮助密码!
    猜你喜欢
    • 2018-05-18
    • 2019-08-03
    • 1970-01-01
    • 2020-11-01
    • 2021-05-27
    • 2019-04-30
    • 2021-05-24
    • 2018-07-24
    • 2022-12-20
    相关资源
    最近更新 更多