【问题标题】:No sound emitted from discord botdiscord bot没有声音
【发布时间】:2020-09-12 17:50:44
【问题描述】:

我目前正在使用 Discord.js v12(Ubuntu 20.04,Node.js v14.0.0),但我无法播放任何声音。

示例代码(voice_connection 指定docs 中定义的 VoiceConnection 实例):

const ytdl = require("ytdl-core-discord");
...
const data = await ytdl(/* some youtube url */, { filter: "audioonly" });
const dispatcher = voice_connection.play(data);

我已经安装了ffmpeg@0.0.4opusscript@0.0.7@discordjs/opus@0.3.2ffmpeg-static@4.0.1

此外,在监听调度员的debug 事件时,我在运行代码大约 10 秒后收到以下错误:

Error: ffmpeg stream: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:92:16) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

最终目标是:修复机器人不播放任何声音、本地文件或远程 URL 的问题。

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:
    const channel = message.member.voice.channel;
        channel.join().then(connection => {
            const dispatcher = connection.play(path.join(__dirname + 'path.mp3'));
            dispatcher.on('speaking', speaking => {
                if(!speaking) channel.leave();
            });
        }).catch(err => console.log(err));
    

    你可以尝试用这种方式播放音频文件,我已经测试过了,它适合我!

    【讨论】:

      猜你喜欢
      • 2019-04-11
      • 2021-11-07
      • 1970-01-01
      • 2022-12-11
      • 2021-12-16
      • 2021-04-15
      • 1970-01-01
      • 2021-01-12
      相关资源
      最近更新 更多