检查特定用户 ID 是否在语音频道中?

时间:2021-02-03 14:45:20

标签: python discord.py

嘿,我正在尝试检查特定用户是否在语音频道中。检索频道中的用户有效,但我无法通过“if”找出其中是否存在某个 ID。我从 Python 列表中获取用户 ID。我不知道该怎么办,请帮忙:)

@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

1 个答案:

答案 0 :(得分:0)

VoiceChannel 有属性 members,它返回连接到语音频道的成员列表,您可以使用 Guild.get_member 获取一个 discord.Member 实例并进行比较如果成员在语音频道中,则使用 in 关键字

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")

参考: