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