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

Diff of /trunk/src/utils/getMember.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 186 by rakin, Mon Jul 29 17:28:56 2024 UTC
# Line 1  Line 1 
1  import { CommandInteraction, GuildMember, Message, User } from "discord.js";  import { CommandInteraction, GuildMember, Message, User } from "discord.js";
2  import CommandOptions from "../types/CommandOptions";  import CommandOptions from "../types/CommandOptions";
3    import { parseMember } from './parseInput';
4    
5  export default async function getMember(msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<GuildMember | null | undefined> {  export default async function getMember(msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<GuildMember | null | undefined> {
6      if (options.normalArgs[index] === undefined)      if (options.normalArgs[index] === undefined)
7          return null;          return null;
8            
     console.log('here');  
       
     if (msgInteraction.mentions.members?.at(index))  
         return await msgInteraction.mentions.members?.at(index);  
   
     console.log(2);  
       
   
9      const arg = await options.normalArgs[index];      const arg = await options.normalArgs[index];
10    
11      if (arg.indexOf('#') !== -1) {      if (arg.indexOf('#') !== -1) {
12          return await msgInteraction.guild?.members.cache.find(m => m.user.tag === arg);          return await msgInteraction.guild?.members.cache.find(m => m.user.tag === arg);
13      }      }
14    
     return await msgInteraction.guild?.members.fetch(arg);  
 }  
15        const parsed = await parseMember(msgInteraction.guild!, arg);
16    
17        if (parsed) {
18            return parsed;
19        }
20        
21        try {
22            return await msgInteraction.guild?.members.fetch(arg);
23        }
24        catch (e) {
25            console.log(e);
26            return null;
27        }
28    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26