Discord.js: Leaving from guild without leaving voice, not updating list of members in voice

Created on 4 Nov 2018  Â·  2Comments  Â·  Source: discordjs/discord.js

If someone leaving server without leaving voice channel, and we trying to get list of users in this voice channel, discord.js not removing him from list.

Code:


const members = voiceChannel.members; 
// For example member A and B in voice channel.
// Member A leaving server without leaving voice channel before it
console.log(members); // Logging what member A and B still in voice channel

How I'm fixing it:


// To fix it, just need to sort it
let members = voiceChannel.members;
// Filtering users by containing in guild members
members = members.filter(member => message.guild.members.has(member.id));
// And if member A leave like before, we'll don't have this problem
console.log(members); //Logging what member B still in voice channel

Further details:

  • discord.js version: 11.4.2
  • Node.js version: 8.11.1
  • Operating system: Microsoft Windows [Version 10.0.17134.345]
  • Priority this issue should have: low
low caching bug

Most helpful comment

Tested it with creating simple bot, with simple command.

Joined with friend in voice, writing test, bot replying this:
image

Friend leaved from server without leaving voice and bot replying this:
image

Friend joined again and bot replying this:
image

@amishshah Thanks for fixing this problem ヾ(^∇^)

All 2 comments

The above commit should fix the issue, please test it!

Tested it with creating simple bot, with simple command.

Joined with friend in voice, writing test, bot replying this:
image

Friend leaved from server without leaving voice and bot replying this:
image

Friend joined again and bot replying this:
image

@amishshah Thanks for fixing this problem ヾ(^∇^)

Was this page helpful?
0 / 5 - 0 ratings