11'use strict' ;
22
3+ const process = require ( 'node:process' ) ;
34const { userMention } = require ( '@discordjs/builders' ) ;
5+ const { calculateUserDefaultAvatarIndex } = require ( '@discordjs/rest' ) ;
46const { DiscordSnowflake } = require ( '@sapphire/snowflake' ) ;
57const Base = require ( './Base' ) ;
68const TextBasedChannel = require ( './interfaces/TextBasedChannel' ) ;
79const UserFlagsBitField = require ( '../util/UserFlagsBitField' ) ;
810
11+ let tagDeprecationEmitted = false ;
12+
913/**
1014 * Represents a user on Discord.
1115 * @implements {TextBasedChannel}
@@ -41,6 +45,16 @@ class User extends Base {
4145 this . username ??= null ;
4246 }
4347
48+ if ( 'global_name' in data ) {
49+ /**
50+ * The global name of this user
51+ * @type {?string }
52+ */
53+ this . globalName = data . global_name ;
54+ } else {
55+ this . globalName ??= null ;
56+ }
57+
4458 if ( 'bot' in data ) {
4559 /**
4660 * Whether or not the user is a bot
@@ -53,7 +67,8 @@ class User extends Base {
5367
5468 if ( 'discriminator' in data ) {
5569 /**
56- * A discriminator based on username for the user
70+ * The discriminator of this user
71+ * <info>`'0'`, or a 4-digit stringified number if they're using the legacy username system</info>
5772 * @type {?string }
5873 */
5974 this . discriminator = data . discriminator ;
@@ -154,7 +169,8 @@ class User extends Base {
154169 * @readonly
155170 */
156171 get defaultAvatarURL ( ) {
157- return this . client . rest . cdn . defaultAvatar ( this . discriminator % 5 ) ;
172+ const index = this . discriminator === '0' ? calculateUserDefaultAvatarIndex ( this . id ) : this . discriminator % 5 ;
173+ return this . client . rest . cdn . defaultAvatar ( index ) ;
158174 }
159175
160176 /**
@@ -188,12 +204,33 @@ class User extends Base {
188204 }
189205
190206 /**
191- * The Discord "tag" (e.g. `hydrabolt#0001`) for this user
207+ * The tag of this user
208+ * <info>This user's username, or their legacy tag (e.g. `hydrabolt#0001`)
209+ * if they're using the legacy username system</info>
192210 * @type {?string }
193211 * @readonly
212+ * @deprecated Use {@link User#username} instead.
194213 */
195214 get tag ( ) {
196- return typeof this . username === 'string' ? `${ this . username } #${ this . discriminator } ` : null ;
215+ if ( ! tagDeprecationEmitted ) {
216+ process . emitWarning ( 'User#tag is deprecated. Use User#username instead.' , 'DeprecationWarning' ) ;
217+ tagDeprecationEmitted = true ;
218+ }
219+
220+ return typeof this . username === 'string'
221+ ? this . discriminator === '0'
222+ ? this . username
223+ : `${ this . username } #${ this . discriminator } `
224+ : null ;
225+ }
226+
227+ /**
228+ * The global name of this user, or their username if they don't have one
229+ * @type {?string }
230+ * @readonly
231+ */
232+ get displayName ( ) {
233+ return this . globalName ?? this . username ;
197234 }
198235
199236 /**
0 commit comments