mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
feat: Add Locales to Interactions (#7131)
Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com>
This commit is contained in:
@@ -74,6 +74,18 @@ class Interaction extends Base {
|
|||||||
* @type {?Readonly<Permissions>}
|
* @type {?Readonly<Permissions>}
|
||||||
*/
|
*/
|
||||||
this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null;
|
this.memberPermissions = data.member?.permissions ? new Permissions(data.member.permissions).freeze() : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 in
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.guildLocale = data.guild_locale ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -1316,6 +1316,8 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
|||||||
public user: User;
|
public user: User;
|
||||||
public version: number;
|
public version: number;
|
||||||
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
public memberPermissions: CacheTypeReducer<Cached, Readonly<Permissions>>;
|
||||||
|
public locale: string;
|
||||||
|
public guildLocale: CacheTypeReducer<Cached, string, string, string>;
|
||||||
public inGuild(): this is Interaction<'raw' | 'cached'>;
|
public inGuild(): this is Interaction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is Interaction<'cached'>;
|
public inCachedGuild(): this is Interaction<'cached'>;
|
||||||
public inRawGuild(): this is Interaction<'raw'>;
|
public inRawGuild(): this is Interaction<'raw'>;
|
||||||
|
|||||||
@@ -955,12 +955,17 @@ client.on('interactionCreate', async interaction => {
|
|||||||
expectAssignable<GuildMember>(interaction.member);
|
expectAssignable<GuildMember>(interaction.member);
|
||||||
expectNotType<ChatInputCommandInteraction<'cached'>>(interaction);
|
expectNotType<ChatInputCommandInteraction<'cached'>>(interaction);
|
||||||
expectAssignable<Interaction>(interaction);
|
expectAssignable<Interaction>(interaction);
|
||||||
|
expectType<string>(interaction.guildLocale);
|
||||||
} else if (interaction.inRawGuild()) {
|
} else if (interaction.inRawGuild()) {
|
||||||
expectAssignable<APIInteractionGuildMember>(interaction.member);
|
expectAssignable<APIInteractionGuildMember>(interaction.member);
|
||||||
expectNotAssignable<Interaction<'cached'>>(interaction);
|
expectNotAssignable<Interaction<'cached'>>(interaction);
|
||||||
|
expectType<string>(interaction.guildLocale);
|
||||||
|
} else if (interaction.inGuild()) {
|
||||||
|
expectType<string>(interaction.guildLocale);
|
||||||
} else {
|
} else {
|
||||||
expectType<APIInteractionGuildMember | GuildMember | null>(interaction.member);
|
expectType<APIInteractionGuildMember | GuildMember | null>(interaction.member);
|
||||||
expectNotAssignable<Interaction<'cached'>>(interaction);
|
expectNotAssignable<Interaction<'cached'>>(interaction);
|
||||||
|
expectType<string | null>(interaction.guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isContextMenuCommand()) {
|
if (interaction.isContextMenuCommand()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user