(discord.py) Getting a list of all of the members in a specific voice channel

Matthew Kopie picture Matthew Kopie · Apr 29, 2018 · Viewed 10.5k times · Source

So I'm attempting to write a raiding bot for my raiding discord using the discord.py library in python. This scripts is supposed to be forming a list of members in the voice channel for raiding. For some reason, this script is not working. Whenever memids is printed, it just prints an empty list.

If anyone is familiar with discord.py and could tell me why this isn't working, please do. It's really troubling me and I have tried everything in my knowledge to fix it.

#find raiding
        voice_channel = discord.utils.get(ctx.message.server.channels, id = '440014722587426816')

        #finds the members
        members = voice_channel.voice_members

        memids = []

        for member in members:
            memids.append(member.id)

        print(memids)

Answer

abccd picture abccd · Apr 29, 2018

There isn't much to go on from your question. I believe your problem is that the id that you provided to utils.get(...) isn't the correct id of the voice channel. This is probably the reason to why you're always getting an empty list.

voice_members

A list of Members that are currently inside this voice channel. If type is not ChannelType.voice then this is always an empty array.

If you're not fully sure about the voice channel's actual id, I suggest you search by the name and type (discord.ChannelType.voice):

voice_channel = discord.utils.get(ctx.message.server.channels, name="channelname", type=discord.ChannelType.voice)