Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
558 views
in Technique[技术] by (71.8m points)

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

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you know the id of the channel you can do it this way. Works for me :D

channel = client.get_channel(1234567890) #gets the channel you want to get the list from

members = channel.members #finds members connected to the channel

memids = [] #(list)
for member in members:
    memids.append(member.id)

print(memids) #print info

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...