/[sudobot]/trunk/src/commands/information/RoleListCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/information/RoleListCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2875 byte(s)
chore: eslint autofix
1 import { CommandInteraction, Role } from 'discord.js';
2 import BaseCommand from '../../utils/structures/BaseCommand';
3 import DiscordClient from '../../client/Client';
4 import InteractionOptions from '../../types/InteractionOptions';
5 import MessageEmbed from '../../client/MessageEmbed';
6
7 export default class RoleListCommand extends BaseCommand {
8 supportsInteractions: boolean = true;
9 supportsLegacy = false;
10
11 constructor() {
12 super('rolelist', 'information', []);
13 }
14
15 async run(client: DiscordClient, msg: CommandInteraction, options: InteractionOptions) {
16 let role: Role | null = null, page = 1;
17
18 if (options.options.getRole('role'))
19 role = <Role> options.options.getRole('role');
20
21 if (options.options.getInteger('page'))
22 page = <number> options.options.getInteger('page');
23
24 if (!role) {
25 const roles = await msg.guild!.roles.cache.toJSON();
26
27 let str = ``;
28 let limit = 15, i = 1, offset = (page - 1) * limit;
29
30 if (offset >= roles.length) {
31 await msg.reply({
32 content: "Invalid page number.",
33 ephemeral: true
34 });
35
36 return;
37 }
38
39 for await (const role of roles) {
40 if (role.id === msg.guild!.id)
41 continue;
42
43 i++;
44
45 if (offset >= (i - 1))
46 continue;
47
48 if ((limit + offset) < (i - 1))
49 break;
50
51 str += `${role.name} - ${role.id} - ${role.members.size} Members - ${role.hexColor}\n`;
52 }
53
54 await msg.reply({
55 content: "**Role List (" + page + ")**:\n\n```" + str + '```',
56 });
57 }
58 else {
59 await msg.reply({
60 embeds: [
61 new MessageEmbed()
62 .setAuthor({
63 name: `Role Information`
64 })
65 .setColor(role.hexColor)
66 .addFields([
67 {
68 name: 'Name',
69 value: role.name
70 },
71 {
72 name: 'Color',
73 value: role.hexColor
74 },
75 {
76 name: 'Members',
77 value: role.members.size + ''
78 },
79 {
80 name: 'Bot Role',
81 value: role.members.size === 1 && role.members.first()?.user.bot ? 'Yes' : 'No'
82 }
83 ])
84 ]
85 });
86 }
87 }
88 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26