如何从所有语音通道获取所有用户的总数和名称Disocrd?
答
您需要访问语音通道对象。我建议你使用语音通道的ID。该命令可能如下所示:
@client.command(pass_context = True)
async def vcmembers(ctx, voice_channel_id):
#First getting the voice channel object
voice_channel = discord.utils.get(ctx.message.server.channels, id = voice_channel_id)
if not voice_channel:
return await client.say("That is not a valid voice channel.")
members = voice_channel.voice_members
member_names = '\n'.join([x.name for x in members])
embed = discord.Embed(title = "{} member(s) in {}".format(len(members), voice_channel.name),
description = member_names,
color=discord.Color.blue())
return await client.say(embed = embed)
,并会像这样工作:
在哪里到底有多少是通道ID。如果您不知道如何获取频道ID,请右键点击该频道并点击复制ID。
如果你不能看到拷贝ID,打开开发模式在Settings > Appearance > Developer Mode
你尝试过什么和你在哪里卡住了? – Wright
@Wright我找到了这个http://discordpy.readthedocs.io/en/latest/api.html#channel和idk如何获取voice_members –