因此,我正在尝试使用python中的discord.py库为我的raiding discord编写一个raiding bot。这个脚本应该在语音通道中形成一个成员列表以进行突袭。出于某种原因,此脚本无法正常工作。每当打印出memids时,它只会打印一个空列表。
如果有人熟悉discord.py并且可以告诉我为什么这不起作用,请这样做。这真让我烦恼,我已经尝试了所有知识来解决它。
#find raiding
voice_channel = discord.utils.get(ctx.message.server.channels, id = '440014722587426816')
#finds the members
members = voice_channel.voice_members
memids = []
for member in members:
memids.append(member.id)
print(memids)
你的问题没有太多可以继续下去。我相信你的问题是你提供给id
的utils.get(...)
不是语音频道的正确ID。这可能就是为什么你总是得到一个空列表的原因。
目前位于此语音频道内的
Members
列表。如果type
不是ChannelType.voice
那么这总是一个空数组。
如果你不完全确定语音通道的实际id
,我建议你搜索名称和类型(discord.ChannelType.voice
):
voice_channel = discord.utils.get(ctx.message.server.channels, name="channelname", type=discord.ChannelType.voice)
我知道频道ID,我建议使用
voice_channel = client.get_channel(channel_id)
相反(documentation here)。如果你正在使用discord.py-rewrite,你也可以使用:
voice_client = ctx.guild.get_channel(channel_id)
如果你正在寻找的频道是在上下文公会(documentation here)。