1 |
rakinar2 |
577 |
import { CommandInteraction, GuildMember, Message, User } from "discord.js"; |
2 |
|
|
import CommandOptions from "../types/CommandOptions"; |
3 |
|
|
import { parseMember } from './parseInput'; |
4 |
|
|
|
5 |
|
|
export default async function getMember(msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<GuildMember | null | undefined> { |
6 |
|
|
if (options.normalArgs[index] === undefined) |
7 |
|
|
return null; |
8 |
|
|
|
9 |
|
|
const arg = await options.normalArgs[index]; |
10 |
|
|
|
11 |
|
|
if (arg.indexOf('#') !== -1) { |
12 |
|
|
return await msgInteraction.guild?.members.cache.find(m => m.user.tag === arg); |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
const parsed = await parseMember(msgInteraction.guild!, arg); |
16 |
|
|
|
17 |
|
|
if (parsed) { |
18 |
|
|
return parsed; |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
try { |
22 |
|
|
return await msgInteraction.guild?.members.fetch(arg); |
23 |
|
|
} |
24 |
|
|
catch (e) { |
25 |
|
|
console.log(e); |
26 |
|
|
return null; |
27 |
|
|
} |
28 |
|
|
} |