检查语音频道中是否有特定的用户id?

2024-09-29 19:36:02 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,我正在检查一个特定的用户是否在一个语音频道。在一个频道中检索用户是可行的,但我无法用“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

Tags: 用户inclientidifchannelkeys频道
1条回答
网友
1楼 · 发布于 2024-09-29 19:36:02

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

参考资料:

相关问题 更多 >

    热门问题