“TypeError [ERR_INVALID_ARG_TYPE]” - MP3和VC

问题描述 投票:0回答:2

当我的不和谐机器人试图在语音通道中播放MP3文件时,我遇到了一个错误。

我的代码:

if(message.member.voiceChannel){

        const connection = await message.member.voiceChannel.join();
        const dispatcher = connection.playFile('./resources/shamebell.mp3');

        dispatcher.on('finish', () => {
            console.log('Finished playing!');
          });

          dispatcher.destroy(); // end the stream
}

机器人在尝试播放MP3文件时遇到错误。它加入了用户所处的语音通道。机器人应该加入VC,然后播放MP3文件然后离开。

调度程序出错:

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string

我尝试过使用绝对路径以及MP3的相对路径。安装了FFMPEG并设置了Windows PATH,并安装了NPM“ffmpeg-binaries”:“^ 3.2.2-3”。

connection.playFile('./resources/shamebell.mp3');换到connection.play('./resources/shamebell.mp3');在14:43给出错误connection.play is not a function

任何有关解决此问题的帮助将不胜感激:)

安装了Discordv12的新代码:

const connection = await message.member.voice.channel.join();
const dispatcher = connection.play('resources/shamebell.mp3');

dispatcher.on('finish', () => {
    console.log('Finished playing!');
  });
  dispatcher.destroy();

同样的问题:

TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string

MP3文件的路径:C:\ Users \ Test \ Desktop \ bot \ BotTest \ resources \ shamebell.mp3

node.js ffmpeg mp3 typeerror discord.js
2个回答
2
投票

我在VSC中使用了调试器,事实证明ffmpeg-static是个问题。错误被掩盖了。

Error: Cannot find module 'ffmpeg-static'

通过npm安装ffmpeg-static解决了这个问题。

现在可以播放MP3了


1
投票

要使用.play()你需要安装discord.js v12 wich推荐用于Voice Stuff做npm i discordjs/discord.js这将为你提供最新版本。

警告discord.js master / v12有重大变化,但完整的语音重写和许多错误修复。

© www.soinside.com 2019 - 2024. All rights reserved.