0

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?

caluthan
  • 47
  • 4
  • Where do you define `users`? – Lucas May 12 '21 at 15:30
  • >Where do you define ```users```? --- I didn't. This was a comment before testing it here. It is different in my actual code. Updated it here. Thanks for pointing it out. It was equal to ```channel.members``` – caluthan May 12 '21 at 15:33
  • Have you enabled `intents.members` in your dashboard and in your code? – LoahL May 12 '21 at 16:18
  • No, I haven't. At least not consciously. What is that and what does it? – caluthan May 12 '21 at 16:34
  • See this answer: https://stackoverflow.com/questions/67346581/discord-py-know-if-user-exists-in-server/67346612#67346612 without enabling them, you don't have access to the member list and can't query any members – LoahL May 12 '21 at 16:36

0 Answers0