【问题标题】:Check if Specific user id is in Voice Channel?检查特定用户 ID 是否在语音通道中?
【发布时间】:2021-05-07 19:42:26
【问题描述】:

嘿,我正在尝试检查特定用户是否在语音频道中。检索频道中的用户是可行的,但如果某个 id 在那里,我无法通过“if”找到。我从 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

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

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

    参考:

    【讨论】:

    • 嗯,是的,频道成员列表是空的,我用不同的频道对其进行了测试,但它不起作用
    • 你启用intents.members了吗?
    • 哦,我该怎么做?对不起我的错
    • 看看我以前的一个answers
    猜你喜欢
    • 2021-05-03
    • 2021-03-30
    • 2021-08-18
    • 2021-05-01
    • 2020-11-21
    • 2023-03-03
    • 2019-07-03
    • 2021-04-13
    • 2021-12-21
    相关资源
    最近更新 更多