From 7022ba0d8d911aed04a2208cbbc2df1c4b4f786c Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Mon, 20 Dec 2021 14:40:57 -0500 Subject: [PATCH 1/4] feat: add locales to interactions --- packages/discord.js/src/structures/Interaction.js | 12 ++++++++++++ packages/discord.js/typings/index.d.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/packages/discord.js/src/structures/Interaction.js b/packages/discord.js/src/structures/Interaction.js index 2c7739d9f2ee..eed62bf9b51f 100644 --- a/packages/discord.js/src/structures/Interaction.js +++ b/packages/discord.js/src/structures/Interaction.js @@ -74,6 +74,18 @@ class Interaction extends Base { * @type {?Readonly} */ this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null; + + /** + * The locale of the member who invoked this interaction + * @type {string} + */ + this.locale = data.locale; + + /** + * The preferred guild locale from where this interaction was sent + * @type {?string} + */ + this.guildLocale = data.guild_locale ?? null; } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 9681022c7432..e4e4188cce8a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1316,6 +1316,8 @@ export class Interaction extends Base { public user: User; public version: number; public memberPermissions: CacheTypeReducer>; + public locale: string; + public guildLocale: string | null; public inGuild(): this is Interaction<'raw' | 'cached'>; public inCachedGuild(): this is Interaction<'cached'>; public inRawGuild(): this is Interaction<'raw'>; From 244f794e7e8335fdf2360f889de28789970008b7 Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Mon, 20 Dec 2021 14:45:03 -0500 Subject: [PATCH 2/4] chore: adjust wording --- packages/discord.js/src/structures/Interaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/structures/Interaction.js b/packages/discord.js/src/structures/Interaction.js index eed62bf9b51f..6a3ae103418f 100644 --- a/packages/discord.js/src/structures/Interaction.js +++ b/packages/discord.js/src/structures/Interaction.js @@ -82,7 +82,7 @@ class Interaction extends Base { this.locale = data.locale; /** - * The preferred guild locale from where this interaction was sent + * The preferred locale from the guild this interaction was sent from * @type {?string} */ this.guildLocale = data.guild_locale ?? null; From 9744d80bf4f6c97bcd3670a46f4d5ec6fddc4a11 Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:00:17 -0500 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> --- packages/discord.js/src/structures/Interaction.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/discord.js/src/structures/Interaction.js b/packages/discord.js/src/structures/Interaction.js index 6a3ae103418f..de1f829ee80d 100644 --- a/packages/discord.js/src/structures/Interaction.js +++ b/packages/discord.js/src/structures/Interaction.js @@ -76,13 +76,13 @@ class Interaction extends Base { this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null; /** - * The locale of the member who invoked this interaction + * The locale of the user who invoked this interaction * @type {string} */ this.locale = data.locale; /** - * The preferred locale from the guild this interaction was sent from + * The preferred locale from the guild this interaction was sent in * @type {?string} */ this.guildLocale = data.guild_locale ?? null; From c9d09f466748585228b6a887ab488377d1ebed47 Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Wed, 22 Dec 2021 13:38:08 -0500 Subject: [PATCH 4/4] types: narrow guild locale based on guild state --- packages/discord.js/typings/index.d.ts | 2 +- packages/discord.js/typings/index.test-d.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index e4e4188cce8a..663800ecb59a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1317,7 +1317,7 @@ export class Interaction extends Base { public version: number; public memberPermissions: CacheTypeReducer>; public locale: string; - public guildLocale: string | null; + public guildLocale: CacheTypeReducer; public inGuild(): this is Interaction<'raw' | 'cached'>; public inCachedGuild(): this is Interaction<'cached'>; public inRawGuild(): this is Interaction<'raw'>; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index f99106651fb6..62ac52cf2c04 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -955,12 +955,17 @@ client.on('interactionCreate', async interaction => { expectAssignable(interaction.member); expectNotType>(interaction); expectAssignable(interaction); + expectType(interaction.guildLocale); } else if (interaction.inRawGuild()) { expectAssignable(interaction.member); expectNotAssignable>(interaction); + expectType(interaction.guildLocale); + } else if (interaction.inGuild()) { + expectType(interaction.guildLocale); } else { expectType(interaction.member); expectNotAssignable>(interaction); + expectType(interaction.guildId); } if (interaction.isContextMenuCommand()) {