Restcord API调用listGuildMembers无结果及email返回NULL求助
listGuildMembers Issues Let's break down your problems and walk through targeted fixes step by step:
1. Empty Results in Stable Restcord Version
You noted that three different calls to listGuildMembers returned empty results in the stable release, but started working after switching to the dev branch. This is almost certainly a bug in the stable version that's already been patched in the development branch. Here's what you can do:
- Stick with the dev branch temporarily until a stable update rolls out with the fix.
- Double-check that your bot has the
GUILD_MEMBERSprivileged intent enabled in the Discord Developer Portal (under your bot's "Privileged Gateway Intents" section) and that your bot token includes theguilds.members.readscope. Missing these permissions can also lead to empty member lists.
Your test calls for reference:
// Attempt 1 $users = $client->guild->listGuildMembers(['guild.id' => 451261315667853312, 'limit' => 25]); // Attempt 2 $users = $client->guild->listGuildMembers(['guild.id' => 451261315667853312, 'limit' => 25, 'after'=>0]); // Attempt 3 $users = $client->guild->listGuildMembers(['guild.id' => 451261315667853312, 'limit' => 25, 'after'=>450894467260743690]); // Guild owner ID
2. NULL Email Field in Dev Branch
The email field returning NULL is almost always tied to Discord's API permissions and scopes, not a Restcord issue. For Discord to return a user's email, all these conditions must be satisfied:
- Your bot must be authorized with the
emailOAuth2 scope (enable this in your app's OAuth2 settings in the Discord Developer Portal). - The user must have explicitly granted your app permission to access their email during the OAuth2 authorization flow—note that just being a member of the guild doesn't automatically grant this access.
- The user's privacy settings allow their email to be shared with authorized apps.
If you're trying to fetch emails without going through the OAuth2 authorization flow for each user, Discord won't return the email field, even if your bot has the correct intents.
内容的提问来源于stack exchange,提问作者Jafer.balti

