【问题标题】:"TypeError [ERR_INVALID_ARG_TYPE]" - MP3 & VC“类型错误 [ERR_INVALID_ARG_TYPE]”- MP3 和 VC
【发布时间】:2019-08-18 08:07:58
【问题描述】:

我的 discord 机器人尝试在语音频道中播放 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


    【解决方案1】:

    我在 VSC 中使用了调试器,结果发现 ffmpeg-static 是问题所在。错误已被屏蔽。

    Error: Cannot find module 'ffmpeg-static'

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

    现在可以播放 MP3

    【讨论】:

      【解决方案2】:

      要使用.play(),您需要安装discord.js v12,建议通过npm i discordjs/discord.js 安装Voice Stuff,这将为您提供最新版本。

      警告discord.jsmaster/v12 有重大更改,但进行了完整的语音重写和许多错误修复。

      【讨论】:

      • 已安装 npm i discordjs/discord.js 并将 playFile 更改为 connection.play('./resources/shamebell.mp3'); 但现在没有任何反应。机器人甚至没有加入 VC
      • 我从 if 中删除了所有内容,它现在加入了频道,但说了同样的话 TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string
      猜你喜欢
      • 2020-12-26
      • 2021-11-26
      • 1970-01-01
      • 2020-07-13
      • 2022-01-10
      • 2020-12-03
      • 2021-04-16
      • 2022-01-12
      • 2017-07-10
      相关资源
      最近更新 更多