Users
This manager helps retrieve basic user information for any user on Discord.
Data Models
User Struct
| name | type | description |
|---|---|---|
| Id | Int64 | the user's id |
| Username | string | their name |
| Discriminator | string | the user's unique discrim |
| Avatar | string | the hash of the user's avatar |
| Bot | bool | if the user is a bot user |
UserFlag Enum
| name | value | description |
|---|---|---|
| Partner | 2 | Discord Partner |
| HypeSquadEvents | 4 | HypeSquad Events participant |
| HypeSquadHouse1 | 64 | House Bravery |
| HypeSquadHouse2 | 128 | House Brilliance |
| HypeSquadHouse3 | 256 | House Balance |
PremiumType Enum
| name | value | description |
|---|---|---|
| None | 0 | Not a Nitro subscriber |
| Tier1 | 1 | Nitro Classic subscriber |
| Tier2 | 2 | Nitro subscriber |
GetCurrentUser
Fetch information about the currently connected user account. If you're interested in getting more detailed information about a user—for example, their email—check out our GetCurrentUser API endpoint. You'll want to call this with an authorization header of Bearer <token>, where <token> is the token retrieved from a standard OAuth2 Authorization Code Grant flow.
Returns a Discord.User.
Parameters
None
Example
csvar user = userManager.GetCurrentUser();Console.WriteLine("Connected to user {0}", user.Id);
GetUser
Get user information for a given id.
Returns a Discord.Result and ref Discord.User via callback.
Parameters
| name | type | description |
|---|---|---|
| userId | Int64 | the id of the user to fetch |
Example
csuserManager.GetUser(userId, (Discord.Result result, ref Discord.User user) =>{if (result == Discord.Result.Ok){Console.WriteLine("User {0} is {1}", user.Id, user.Username);}});
GetCurrentUserPremiumType
Get the PremiumType for the currently connected user.
Returns Discord.PremiumType.
Parameters
None
Example
csvar userManager = discord.GetUserManager();var premiumType = userManager.GetCurrentUserPremiumType();switch (premiumType){case PremiumType.None:Console.WriteLine("User is not a Nitro subscriber");case PremiumType.Tier1:Console.WriteLine("User has Nitro Classic");case PremiumType.Tier2:Console.WriteLine("User has Nitro");default:return;}
CurrentUserHasFlag
See whether or not the current user has a certain UserFlag on their account.
Returns bool.
Parameters
| name | type | description |
|---|---|---|
| flag | UserFlag | the flag to check on the user's account |
Example
csvar userManager = discord.GetUserManager();if (userManager.CurrentUserHasFlag(Discord.UserFlag.HypeSquadHouse1)){Console.WriteLine("User is a member of House Bravery!");}
OnCurrentUserUpdate
Fires when the User struct of the currently connected user changes. They may have changed their avatar, username, or something else.
Parameters
None
Example
csvar userManager = discord.GetUserManager();// GetCurrentUser will error until this fires once.userManager.OnCurrentUserUpdate += () => {var currentUser = userManager.GetCurrentUser();Console.WriteLine(currentUser.Username);Console.WriteLine(currentUser.Id);Console.WriteLine(currentUser.Discriminator);Console.WriteLine(currentUser.Avatar);};
Example: Fetching Data About a Discord User
csvar discord = new Discord.Discord(clientId, Discord.CreateFlags.Default);var userManager = discord.GetUserManager();userManager.GetUser(450795363658366976, (Discord.Result result, ref Discord.User user) =>{if (result == Discord.Result.Ok){Console.WriteLine("user fetched: {0}", user.Username);}else{Console.WriteLine("user fetch error: {0}", result);}});