Discord.js: "speaking" event not triggering

Created on 23 Nov 2019  路  7Comments  路  Source: discordjs/discord.js

There are 2 cases. In first one you speak during bot playing audio and then 'speaking' event will not trigger. In the second one you mute your mic, wait until "I am ready to listen..." and then unmute and speak, then the event triggers.


require('dotenv').config()
const Discord = require('discord.js')
const config = require('./config')

async function playFile(connection, filePath) {
  return new Promise((resolve, reject) => {
    const dispatcher = connection.play(filePath)
    dispatcher.setVolume(1)
    dispatcher.on('start', () => {
      console.log('Playing')
    })
    dispatcher.on('end', () => {
      resolve()
    })
    dispatcher.on('error', (error) => {
      console.error(error)
      reject(error)
    })
  })
}

const discordClient = new Discord.Client()

discordClient.on('ready', () => {
  console.log(`Logged in as ${discordClient.user.tag}!`)
})

discordClient.on('presenceUpdate', async (oldPresence, newPresence) => {
  const member = newPresence.member
  const presence = newPresence
  const memberVoiceChannel = member.voice.channel

  if (!presence || !presence.activity || !presence.activity.name || !memberVoiceChannel) {
    return
  }

  const connection = await memberVoiceChannel.join()

  await playFile(connection, 'anyaudio.mp3')

  console.log('I am ready to listen...')

  connection.on('speaking', (user, speaking) => {
    if (!speaking) {
      console.log('not speaking')
      return
    }

    console.log(`I'm listening to ${user.username}`)
  })
})

discordClient.login(config.discordApiToken)

Further details:

  • discord.js version: master
  • Node.js version: 10.13.0, 10.17.0 and 11.15.1
  • Operating system: Ubuntu 18.04
  • [x] I have also tested the issue on latest master, commit hash: 100360705ae29216f14129bc7a37f3870ec58fc6

UPDATE 24.11.19:
As far as I can tell in VoiceWebSocket#onMessage only one event signaling that user started speaking comes. Then there is nothing and audio stream never ends.

voice bug

Most helpful comment

Using master version of discord.js
node v8.15.1

Given that djs master has a minimum Node requirement of v10, I'm wondering how you don't have far more issues than just the speaking event.

All 7 comments

Experiencing the same or similar issue.

Speaking event will never trigger when I speak in a voicechannel that my bot had also joined.

A suggested fix for a like issue in January failed to work for me as well.
https://github.com/discordjs/discord.js/issues/2929#issuecomment-458584532

Using master version of discord.js
node v8.15.1

Edit: updated node version to v10.15.3
Issue persists.

Using master version of discord.js
node v8.15.1

Given that djs master has a minimum Node requirement of v10, I'm wondering how you don't have far more issues than just the speaking event.

It's funny that with node js v8 + djs v11.5 the same issue is having place. That is why I think something changed in Discord API itself and it's not a djs issue really.

I mean I had audio stream END happily triggering before and then it just broke.

See #3524 and #3578 for more info.

Closing as this issue has been fixed with #3578.

This _has not been fixed_ with #3578 and still requires to manually sent a silence buffer.

I can't seem to reproduce this. For reference, my code and dependencies here.

Note that discord.js has been sending this silence buffer on its own before marking the connection as ready since https://github.com/discordjs/discord.js/commit/f826c9c75e976a8dca3fb4c88c130a1e12147a80 (February 2019).


If you still can reproduce this somehow, open a new issue filling out the template.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tiritto picture tiritto  路  3Comments

smchase picture smchase  路  3Comments

DatMayo picture DatMayo  路  3Comments

Acaretia picture Acaretia  路  3Comments

iCrawl picture iCrawl  路  3Comments