【问题标题】:Discord.js Music bot "TypeError" when playing audio with dispatcher使用调度程序播放音频时的 Discord.js 音乐机器人“TypeError”
【发布时间】:2020-06-06 06:00:04
【问题描述】:

我是 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

【问题讨论】:

  • ...是的,用不和谐的机器人播放音乐是一种痛苦...我做了一个从 youtube 上播放,它有一半的时间和特定的 url 工作...对不起,我无能为力很多,也许你可以检查我的代码github.com/gui3/discord-sandbot/blob/master/commands/play.js
  • 你在 bot 服务器上安装了 ffmpeg 二进制文件吗?
  • 我记得那件事很痛苦github.com/discordjs/discord.js/issues/…
  • 我已经在我的 PC 上正确安装了 ffmpeg,但是当我尝试在我的项目文件夹中运行此命令时:npm install ffmpeg-binaries 我收到一条巨大的错误消息。你想让我在我的问题中发布错误消息吗?

标签: node.js ffmpeg discord.js dispatcher


【解决方案1】:

首先您需要重置您的令牌,切勿将其发布到网上,因为其他人可以使用它来访问和控制您的机器人

here is a good answer你的问题

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

【讨论】:

  • 我忘了不要把我的令牌贴在上面。我确实安装了 FFMPEG 并设置了路径。当我在命令行中键入 ffmpeg 时,我得到了正确的响应。我不确定你还想看什么。控制台中没有任何内容,也没有任何反应。
  • 尝试将其设置为从./Assets/Glory.mp3播放
  • 我还查看了您发送的链接,据我所知,我拥有回答所说的所有内容。
  • 我认为我们正在取得进展。当我将它设置为从 ./Assets/Glory.mp3 播放时,我得到了控制台日志“播放完毕!”立即地。所以我猜是这样。
  • 我更新了很多问题以显示我现在的位置。
猜你喜欢
  • 2020-03-16
  • 2021-05-05
  • 2021-11-29
  • 2021-12-08
  • 1970-01-01
  • 2021-11-22
  • 2020-09-22
  • 2021-07-25
  • 2022-01-04
相关资源
最近更新 更多