'(Discord.py) List of members connected to the voice channel

I tried to do this:

@bot.command()
async def move(ctx):
    channel = bot.get_channel(728854327808229406) 

    members = channel.members 

    print(channel)
    print(channel.members) #print info

But when I start the program, an empty list comes back, even with me connected.

Thank you!

Terminal picture

Discord picture



Solution 1:[1]

It's probably happening because you didn't enable Privileged Gateway intents and your bot can't get members from the channel. Enable Server Members Intent on the Discord Developer site in the Bot section.

discord site screenshot

Then, add this to your code:

intents = discord.Intents.default()
intents.members = True

# choose the one you use:
bot = commands.Bot(command_prefix="your prefix", intents=intents)
bot = discord.Client(intents=intents)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RiveN