Skip to content

Commit

Permalink
refactor: remove required from getMember (#7188)
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Jan 17, 2022
1 parent 3bb4829 commit c90e47f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ class CommandInteractionOptionResolver {
/**
* Gets a member option.
* @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found.
* @returns {?(GuildMember|APIGuildMember)}
* The value of the option, or null if not set and not required.
* The value of the option, or null if the user is not present in the guild or the option is not set.
*/
getMember(name, required = false) {
const option = this._getTypedOption(name, 'USER', ['member'], required);
getMember(name) {
const option = this._getTypedOption(name, 'USER', ['member'], false);
return option?.member ?? null;
}

Expand Down
7 changes: 2 additions & 5 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
APIApplicationCommandPermission,
APIAuditLogChange,
APIButtonComponent,
APIChannel,
APIEmbed,
APIEmoji,
APIInteractionDataResolvedChannel,
Expand Down Expand Up @@ -705,8 +704,7 @@ export interface ApplicationCommandInteractionOptionResolver<Cached extends Cach
getNumber(name: string, required?: boolean): number | null;
getUser(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['user']>;
getUser(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['user']> | null;
getMember(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['member']>;
getMember(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['member']> | null;
getMember(name: string): NonNullable<CommandInteractionOption<Cached>['member']> | null;
getRole(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['role']>;
getRole(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['role']> | null;
getMentionable(
Expand Down Expand Up @@ -781,8 +779,7 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
public getNumber(name: string, required?: boolean): number | null;
public getUser(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['user']>;
public getUser(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['user']> | null;
public getMember(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['member']>;
public getMember(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['member']> | null;
public getMember(name: string): NonNullable<CommandInteractionOption<Cached>['member']> | null;
public getRole(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['role']>;
public getRole(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['role']> | null;
public getMentionable(
Expand Down
2 changes: 0 additions & 2 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,6 @@ client.on('interactionCreate', async interaction => {
expectAssignable<ChatInputCommandInteraction>(interaction);
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
expectType<APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('test'));
expectType<APIInteractionDataResolvedGuildMember>(interaction.options.getMember('test', true));

expectType<APIInteractionDataResolvedChannel>(interaction.options.getChannel('test', true));
expectType<APIRole>(interaction.options.getRole('test', true));
Expand All @@ -1096,7 +1095,6 @@ client.on('interactionCreate', async interaction => {
expectType<ChatInputCommandInteraction>(interaction);
expectType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
expectType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test'));
expectType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true));

expectType<GuildBasedChannel | APIInteractionDataResolvedChannel>(interaction.options.getChannel('test', true));
expectType<APIRole | Role>(interaction.options.getRole('test', true));
Expand Down

0 comments on commit c90e47f

Please sign in to comment.