0

Hey im trying to check if a Specific User is in a Voice Channel. Retrieving the users in a channel works but i can't find out with "if" if a certain id is in there. Im getting the User id from a Python list. I dont know what to do please help :)

@client.command()
async def foo(ctx):
    t = len(memberlist)
    countermem = 0

    for _ in range(t):
        voice_channel = client.get_channel(802195467278352407)
        voice_state = ctx.member.voice
    
        ids = voice_channel.voice_states.keys()
        userid = memberlist[(countermem)]
        channelid = discord.VoiceChannel 

        voice_state = userid.member.voice

        if voice_state is None:
            print ("Somesssssssssssng")



        print(channelid)
        print ("Some thing")
        id = memberlist[(countermem)]
        print(id)

                
        fullstring = voice_channel.voice_states.keys()
        substring = "700388090631421982"

        
        if memberlist[(countermem)] in voice_channel.voice_states.keys():
            print("is in a channel")
            if id in voicestats:
                voicestats[id] += 10
                _savestats()
                print("it worked")
                
                
            else:
                print("was not in stats file")
                
                voicestats[id] = 10
                
                _savestats()
        else:
            print("not in a channel")
        countermem += 1
Spaffel
  • 1
  • 1

1 Answers1

0

VoiceChannel has the attribute members, it returns a list of members that are connected to the voice channel, you can use Guild.get_member to get a discord.Member instance and compare it with the in keyword if the member is in the voice channel

voice_channel = client.get_channel(802195467278352407)
member = ctx.guild.get_member(SOME_ID) # You can use `ctx.author` if you want to check with the user that invoked the command

if member in voice_channel.members:
    print(f"{member} is in the voice channel")
else:
    print(f"{member} is not in the voice channel")

Reference:

Łukasz Kwieciński
  • 14,992
  • 4
  • 21
  • 39