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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (hide annotations)
Mon Jul 29 17:28:26 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1014 byte(s)
Add -setchperms command
1 rakin 62 import { CommandInteraction, Guild, GuildMember, Message, Role, User, MessageMentions } from "discord.js";
2 rakin 60 import CommandOptions from "../types/CommandOptions";
3    
4     export default async function getRole(msgInteraction: Message, options: CommandOptions, index: number = 0): Promise<Role | null | undefined> {
5     if (options.normalArgs[index] === undefined)
6     return null;
7    
8     if (msgInteraction.mentions.roles?.at(index))
9     return await msgInteraction.mentions.roles?.at(index);
10    
11     const arg = await options.normalArgs[index];
12    
13     return await msgInteraction.guild?.roles.fetch(arg);
14 rakin 62 }
15    
16     export async function getRoleRaw(roleString: string, guild: Guild): Promise<Role | null | undefined> {
17     if (roleString === '@everyone')
18     return guild.roles.everyone;
19     else if (MessageMentions.ROLES_PATTERN.test(roleString)) {
20     roleString = roleString.substring(3, roleString.length - 1);
21     }
22    
23     console.log(roleString);
24     return await guild.roles.fetch(roleString);
25 rakin 60 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26