如何获得 discord.Guild 对象 'complete'(即每个成员有 Member.activity 和 Member.voice)? (discord.py)
How can I get a discord.Guild object that is 'complete' (i.e. has Member.activity and Member.voice per member)? (discord.py)
我正在尝试获取不和谐服务器(公会)上特定频道中的活跃用户列表,但是如果我通过以下功能(取自文档)获得公会,它会给我一个 'incomplete' 公会也如文档中所述。有没有办法在不使用命令上下文的情况下获得完整的?
await fetch_guild(guild_id)
This function is a coroutine.
Retrieves a Guild from an ID.
Using this, you will not receive Guild.channels, Guild.members, Member.activity and Member.voice per Member.
Taken from https://discordpy.readthedocs.io/en/stable/api.html?highlight=guild#discord.Client.fetch_guild (docs)
这是我当前的代码:
@tasks.loop(minutes=10)
async def t(self):
guild = await self.client.fetch_guild(<server id>)
afk_channel = guild.afk_channel
for channel in await guild.fetch_channels():
if isinstance(channel, discord.VoiceChannel):
if channel.members and channel != afk_channel:
for member in channel.members:
# do stuff
print(member.display_name, channel.name)
我曾尝试 get_guild(id)
正如 @ŁukaszKwieciński 的 在他的评论中所说,但它返回 None
,事实证明它被调用得太早了(机器人还没有准备好),所以我需要在任务之前放置 await self.client.wait_until_ready()
(另一个带有装饰器的函数 @t.before_loop
)
我正在尝试获取不和谐服务器(公会)上特定频道中的活跃用户列表,但是如果我通过以下功能(取自文档)获得公会,它会给我一个 'incomplete' 公会也如文档中所述。有没有办法在不使用命令上下文的情况下获得完整的?
await fetch_guild(guild_id)
This function is a coroutine.
Retrieves a Guild from an ID.
Using this, you will not receive Guild.channels, Guild.members, Member.activity and Member.voice per Member.
Taken from https://discordpy.readthedocs.io/en/stable/api.html?highlight=guild#discord.Client.fetch_guild (docs)
这是我当前的代码:
@tasks.loop(minutes=10)
async def t(self):
guild = await self.client.fetch_guild(<server id>)
afk_channel = guild.afk_channel
for channel in await guild.fetch_channels():
if isinstance(channel, discord.VoiceChannel):
if channel.members and channel != afk_channel:
for member in channel.members:
# do stuff
print(member.display_name, channel.name)
我曾尝试 get_guild(id)
正如 @ŁukaszKwieciński 的 在他的评论中所说,但它返回 None
,事实证明它被调用得太早了(机器人还没有准备好),所以我需要在任务之前放置 await self.client.wait_until_ready()
(另一个带有装饰器的函数 @t.before_loop
)