Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.Net GetUser By Id Returns null

I was coding a bot for Discord using Discord.net. I have an IGuild where I need to get a User by id, so I'm using:

var user = await guild.GetUserAsync(id, CacheMode.AllowDownload);

This should get the user if cached, and if not, download it. But the user is null every time.

I know the id is correct. Is there a proper way to do this?

The Server has > 1k members so downloading them through DownloadUsersAsync takes way too long.

like image 717
BrainyXS Avatar asked Nov 07 '25 11:11

BrainyXS


1 Answers

Arriving late to the party.

Your problem is a direct consequence of the new Gateway Intents, put in place by Discord on their API.

Not to worry, this is an easy fix. Just go to https://discord.com/developers/applications, select your App, then got to the bot section. You're then looking for this. Just enable Server Members Intent.

If everything went to plan, this should transparently fix your issue without even needing to recompile. Short of that, feel free to ask again.

like image 115
Sakura Isayeki Avatar answered Nov 09 '25 02:11

Sakura Isayeki