【问题标题】:Bot receiver listen only to itselfBot接收器只听自己
【发布时间】:2018-11-30 13:18:49
【问题描述】:

我对 createReceiver 有疑问。我有代码:

client.on('message', message => {
  // Voice only works in guilds, if the message does not come from a guild,
  // we ignore it
  if (!message.guild) return;

  if (message.content === '/q') {
    // Only try to join the sender's voice channel if they are in one themselves

    const voiceChannel = message.member.voiceChannel;

    if (message.member.voiceChannel) {
      message.member.voiceChannel.join()
        .then(connection => { // Connection is an instance of VoiceConnection
            connection.on('error', console.error);

            // const dispatcher = connection.playFile('C:/Denwer/ddradio/lyubov.mp3');

            connection.on('speaking', (user, speaking) => {
                if(speaking) {
                    const receiver = connection.createReceiver();
                    const stream = receiver.createPCMStream(user);

                    stream.on('data', chunk => {
                        console.log(chunk.length);
                    });
                }
            });
        })
        .catch(console.log);
    } else {
      message.reply('');
    }
  }
})

console.log(chunk.length); 仅在播放音乐时工作,那些。只有当机器人说话时。他没有听到其他成员的声音。请告诉我是什么问题

【问题讨论】:

  • 他只会在他自己说话的时候发送pcm,但不发送pcm,当其他用户说话时,一边说话一边说话,对用户也有效。

标签: node.js discord.js


【解决方案1】:

我遇到了同样的问题,我不知道如何永远彻底解决它,但如果你播放一个短音频文件,比如哔声,当机器人加入频道时,你的代码应该可以工作。

【讨论】:

    猜你喜欢
    • 2023-01-19
    • 2014-01-12
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2020-11-23
    相关资源
    最近更新 更多