1 |
import { CommandInteraction, GuildMember, Message, User } from "discord.js"; |
import { Message, User } from "discord.js"; |
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 { parseUser } from './parseInput'; |
5 |
|
|
6 |
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> { |
7 |
if (options.normalArgs[index] === undefined) |
if (options.normalArgs[index] === undefined) |
8 |
return null; |
return null; |
9 |
|
|
|
console.log('here'); |
|
|
|
|
|
if (msgInteraction.mentions.users?.at(index)) |
|
|
return await msgInteraction.mentions.users?.at(index); |
|
|
|
|
|
console.log(2); |
|
|
|
|
10 |
const arg = await options.normalArgs[index]; |
const arg = await options.normalArgs[index]; |
11 |
|
|
12 |
|
console.log(arg); |
13 |
|
|
14 |
if (arg.indexOf('#') !== -1) { |
if (arg.indexOf('#') !== -1) { |
15 |
return await client.users.cache.find(user => user.tag === arg); |
return await client.users.cache.find(user => user.tag === arg); |
16 |
} |
} |
17 |
|
|
|
return await client.users.fetch(arg); |
|
|
} |
|
18 |
|
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 |
|
} |