公会成员不再填充,不能GetUserAsync,因为它仅返回bot,而没有其他人 [英] Guild members are not populated anymore, cannot GetUserAsync as it only returns the bot and no one else
问题描述
由于某种原因,我无法再从该机器人所在的公会中获取任何成员.
For some reason I cannot get any members anymore from the guild the bot is in.
为确保我有用户,我用
DiscordSocketConfig config = new DiscordSocketConfig { AlwaysDownloadUsers = true };
client = new DiscordSocketClient(config);
我响应的事件在连接后很长时间.它将从机器人所在的公会中的渠道本身中获取消息,因此该机器人已连接,正在运行,并且可以看到所有成员.
The event I respond to is long after it has connected. It will pick up messages from the channels themselves in the guild the bot is in, so it's connected, working, and can see all of the members.
我遍历了所有成员,并尝试使用一些调试代码将它们打印出来:
I go through all the members and I'm trying to print them out with some debug code like:
Console.WriteLine("Users:");
foreach (IGuildUser? u in Guild.GetUsersAsync().Result)
Console.WriteLine($" {u.Username} ({u.Id})");
,它只会打印自己.
我在代码中使用此代码的方式如下:
The way I'm using this in my code is like:
Guild.GetUserAsync(user.Id) // user is valid, this is empty for anyone who is not the bot
公会对象上的私有字段 _members
具有1个元素(它本身就是机器人),但其他所有元素(例如: _emojis
,_channels
,以及其他任何缓存的内容).该bot可以在频道中与所有用户聊天,也可以在频道中与所有用户接收消息,因此我不知道为什么它无法获得所有成员.
The private field _members
on the guild object has 1 element (which is itself, the bot), but all the other things (ex: _emojis
, _channels
, any other cached thing) are all fully populated. The bot can talk in channels and receive messages in channels with all the users as well, so I have no idea why it cannot get all the members.
最让我感到困惑的是,这一切都在起作用,然后魔术般地停止了一整夜的工作.公会已经有100多个成员了,所以我不明白为什么它现在突然失败了.
What confuses me the most is that this was all working, and then magically stopped working overnight. The guild has been over 100 members for a while, so I don't understand why it's suddenly failing now.
最重要的是,该机器人具有我所拥有的所有角色,因此它不可能神奇地无法看到其成员.我可以排除机器人的视觉问题.
Most importantly, the bot has all the roles that I have, so there's no way it's magically unable to see the members. I can rule out any visual problems for the bot.
有什么办法可以调试吗?我想念什么吗?我如何让行会的所有成员重新工作?
Any way I can debug this? Am I missing something? How can I get all the members of a guild to work again?
推荐答案
This is a result of Discord enforcing intents.
意图允许您选择加入某些网关事件.当前,GUILD_MEMBERS和GUILD_PRESENCES意图是特权意图".并具有以下效果:
Intents allow you to opt-in to certain gateway events. Currently, the GUILD_MEMBERS and GUILD_PRESENCES intents are "privileged intents" and have the following effects:
- GUILD_MEMBER_ [ADD | UPDATE | REMOVE]要求接收GUILD_MEMBERS意图
- PRESENCE_UPDATE要求接收GUILD_PRESENCES意图
- REQUEST_GUILD_MEMBERS
- 需要GUILD_PRESENCES意图将状态设置为true
- 需要GUILD_MEMBERS意图来请求整个列表(query ='',limit = 0< = n)
- 仅限于请求1个guild_id 使用前缀(query ='prefix',limit = 1< = n< = 100)时
- 最多只能有100个成员
- GUILD_MEMBER_[ADD|UPDATE|REMOVE] requires the GUILD_MEMBERS intent to be received
- PRESENCE_UPDATE requires the GUILD_PRESENCES intent to be received
- REQUEST_GUILD_MEMBERS
- requires GUILD_PRESENCES intent to set presences=true
- requires GUILD_MEMBERS intent to request the whole list (query='', limit=0<=n)
- is limited to requesting 1 guild_id
- is limited to 100 members when using a prefix (query='prefix', limit=1<=n<=100)
默认情况下禁用特权意图.要启用它们:
Privileged intents are disabled by default. To enable them:
- 访问 https://discord.com/developers/applications
- 点击您要启用特权意图的漫游器 导航到"Bot"页面.左侧的标签
- 滚动到特权网关意图"部分
- 启用您想要的意图
- Visit https://discord.com/developers/applications
- Click on the bot where you wish to enable privileged intents
- Navigate to the "Bot" tab on the left
- Scroll to the Privileged Gateway Intents section
- Enable your desired intents
如果您的漫游器有100多个行会,则需要验证您的漫游器: https://dis.gd/bot-verification .如果您的漫游器已经过验证,但是需要请求意图许可,请与Discord支持人员联系: https://dis.gd/contact .
If your bot is in over 100 guilds, you will need to verify your bot: https://dis.gd/bot-verification. If your bot is already verified, but need to request intents permission, contact Discord support: https://dis.gd/contact.
这篇关于公会成员不再填充,不能GetUserAsync,因为它仅返回bot,而没有其他人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!