2 |
import DiscordClient from "../client/Client"; |
import DiscordClient from "../client/Client"; |
3 |
import CommandOptions from "../types/CommandOptions"; |
import CommandOptions from "../types/CommandOptions"; |
4 |
import InteractionOptions from "../types/InteractionOptions"; |
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> { |
export default async function getUser(client: DiscordClient, msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<User | null | undefined> { |
8 |
if (options.normalArgs[index] === undefined) |
if (options.normalArgs[index] === undefined) |
9 |
return null; |
return null; |
10 |
|
|
|
console.log('here'); |
|
|
|
|
|
if (msgInteraction.mentions.users?.at(index)) |
|
|
return await msgInteraction.mentions.users?.at(index); |
|
|
|
|
|
console.log(2); |
|
|
|
|
11 |
const arg = await options.normalArgs[index]; |
const arg = await options.normalArgs[index]; |
12 |
|
|
13 |
|
console.log(arg); |
14 |
|
|
15 |
if (arg.indexOf('#') !== -1) { |
if (arg.indexOf('#') !== -1) { |
16 |
return await client.users.cache.find(user => user.tag === arg); |
return await client.users.cache.find(user => user.tag === arg); |
17 |
} |
} |
18 |
|
|
|
return await client.users.fetch(arg); |
|
|
} |
|
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 |
|
} |