在使用调度程序播放音频时,Discord.js音乐机器人“ TypeError”

时间:2020-02-21 19:08:05

标签: node.js ffmpeg discord.js dispatcher

我是Discord.js的新手,并且试图让该机器人加入语音通道并在计算机上播放音频文件。我一直在遵循本指南:https://discord.js.org/#/docs/main/stable/topics/voice。这是Index.js页面:

Colesbot.on('message', message=>{
    if (message.content === '/join') {
        // Only try to join the sender's voice channel if they are in one themselves
        if (message.member.voiceChannel) {
            message.member.voiceChannel.join().then(connection => {
                message.reply('I have successfully connected to the channel!');

                // To play a file, we need to give an absolute path to it
                const dispatcher = connection.playFile('C:\Users\bobal\Documents\GitHub\Spotify-Playlist-Discord-bot\Assets\Glory.mp3');

                dispatcher.on('end', () => {
                    // The song has finished
                    console.log('Finished playing!');
                  });

                dispatcher.on('error', e => {
                    // Catch any errors that may arise
                    console.log(e);
                  });

                  dispatcher.setVolume(0.5); // Set the volume to 50%
            }).catch(console.log);
    } else {
        message.reply('You need to join a voice channel first!');
      }
    }
 });
exports.run = (client, message, args) => {
    let user = message.mentions.users.first || message.author;
}

已安装FFMPEG,并且已为其设置环境路径。当我在命令行中键入FFMPEG时,我会得到正确的响应。

有人说我需要安装ffmpeg二进制文件,但是当我运行npm install ffmpeg-binaries时,我收到一条错误消息that is here

因此,我尝试安装旧版本,现在使用ffmpeg-binaries@3.2.2-3,但是当我键入/ join时出现错误

[ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object

1 个答案:

答案 0 :(得分:1)

首先,您需要重置令牌,永远不要在线发布令牌,因为其他人可以使用它来访问和控制您的机器人

here is a good answer提问

我认为您需要安装FFMPEG并为其设置环境路径,但是,您能否提供更多信息,控制台日志,行为等