Skip to content

Commit

Permalink
chore: too tired to write descriptive message
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Oct 16, 2021
1 parent 257cb21 commit de34f7b
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/lib/resolvers/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import type { Guild, GuildMember, Snowflake } from 'discord.js';
import { Identifiers } from '../errors/Identifiers';
import { err, ok, Result } from '../parsers/Result';

const memberWithDiscriminatorRegex = /#\d{4}$/;

export async function resolveMember(parameter: string, guild: Guild): Promise<Result<GuildMember, Identifiers.ArgumentMemberError>> {
const member = (await resolveById(parameter, guild)) ?? (await resolveByQuery(parameter, guild));
if (member) return ok(member);
Expand All @@ -17,10 +15,7 @@ async function resolveById(argument: string, guild: Guild): Promise<GuildMember
}

async function resolveByQuery(argument: string, guild: Guild): Promise<GuildMember | null> {
const queryDiscriminator = memberWithDiscriminatorRegex.test(argument);
if (queryDiscriminator) {
argument = argument.substring(0, -4);
}
argument = argument.length > 5 && argument.at(-5) === '#' ? argument.slice(0, -5) : argument;

const members = await guild.members.fetch({ query: argument, limit: 1 }).catch(() => null);
return members?.first() ?? null;
Expand Down

0 comments on commit de34f7b

Please sign in to comment.