/[sudobot]/trunk/src/utils/getUser.ts
ViewVC logotype

Annotation of /trunk/src/utils/getUser.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (hide annotations)
Mon Jul 29 17:28:56 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 940 byte(s)
fix: mention reading strategy (#41)

* fix(commands): ban related commands not working when banning users outside of the server

* fix(utils): reading users/members in the wrong way
1 rakin 51 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 rakin 186 import { parseUser } from './parseInput';
6 rakin 51
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 rakin 186 console.log(arg);
14    
15 rakin 51 if (arg.indexOf('#') !== -1) {
16     return await client.users.cache.find(user => user.tag === arg);
17     }
18    
19 rakin 186 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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26