如何从此值中获取会员 ID?不和谐.py

时间:2021-04-07 13:26:58

标签: python discord.py

您好,我需要获取会员 ID 我尝试了很多方法:

这是值:[, ]

你的价值类型是什么?

如果我使用此代码获取 ID:

@client.command()
async def test123(ctx):
    voice_channel = client.get_channel(channel_id) #i used the channel id but i removed it in this exampl
    members2 = voice_channel.members
    await ctx.send(f"User: {members2} ")

    for index, member in enumerate(members2):
        
        testlol = (id)
        await ctx.send(f"User: {testlol}  ")

我得到这个输出:用户:

我怎样才能得到会员的id,请帮帮我:)

1 个答案:

答案 0 :(得分:0)

要获取语音频道中成员的 ID,您可以创建一个列表并查看语音频道中的所有成员。

看看下面的代码:

@client.command()
async def test123(ctx):
    voice_channel = client.get_channel(ChannelID)
    members = voice_channel.members  # Members that are connected to the channel

    vcmember = []  # Creates a list
    for member in members:
        memids.append(member.id) # Get the IDs/add them to the list
        await ctx.send(f"{vcmember}")

记得导入并激活 Intents