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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
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    }

Legend:
Removed from v.51  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26