I'm trying to get a list of all users/members in the voice channel a certain user who ran the command is in. I manage to get the user and the channel he is in without any problems (tried this by sending a chat message that mentioned the channel, it worked). But when I try to get a list of the users/members connected to the channel it's starting to get weird.
await message.channel.send("called by user " + message.author.name)
voice_state = message.author.voice
if voice_state != None:
channel = voice_state.channel
await message.channel.send(channel.mention)
await message.channel.send(len(channel.members))
for u in channel.members:
await message.channel.send(u.name)
else:
await message.channel.send("user " + message.author.name + " is not currently in a voice channel")
This is the code I used. message
is the message that contained the command. This outputs the correct user and mentions the voice channel he is in (if he is in one). The next command await message.channel.send(len(channel.members))
outputs 0 most of the time, but weirdly gave 2 (the correct number) once instead. Obviously the loop doesn't trigger if the list is of length 0. It wasn't yet implemented when it output 2 once, so I can't tell if it works as intended.
Most of this is just for testing if I get a correct list, which I don't. How can I get a list of users/members in a channel?