1 |
rakin |
344 |
import { Message, User } from "discord.js"; |
2 |
rakin |
51 |
import DiscordClient from "../client/Client"; |
3 |
|
|
import CommandOptions from "../types/CommandOptions"; |
4 |
rakin |
186 |
import { parseUser } from './parseInput'; |
5 |
rakin |
51 |
|
6 |
|
|
export default async function getUser(client: DiscordClient, msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<User | null | undefined> { |
7 |
|
|
if (options.normalArgs[index] === undefined) |
8 |
|
|
return null; |
9 |
|
|
|
10 |
|
|
const arg = await options.normalArgs[index]; |
11 |
|
|
|
12 |
rakin |
186 |
console.log(arg); |
13 |
|
|
|
14 |
rakin |
51 |
if (arg.indexOf('#') !== -1) { |
15 |
|
|
return await client.users.cache.find(user => user.tag === arg); |
16 |
|
|
} |
17 |
|
|
|
18 |
rakin |
186 |
const parsed = await parseUser(client, arg); |
19 |
|
|
|
20 |
|
|
if (parsed) { |
21 |
|
|
return parsed; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
try { |
25 |
|
|
const u = await client.users.fetch(arg); |
26 |
|
|
return u; |
27 |
|
|
} |
28 |
|
|
catch (e) { |
29 |
|
|
console.log(e); |
30 |
|
|
return null; |
31 |
|
|
} |
32 |
|
|
} |