1 |
rakin |
60 |
import { CommandInteraction, Message, Role } from 'discord.js'; |
2 |
|
|
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
|
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
|
|
import getRole from '../../utils/getRole'; |
8 |
|
|
|
9 |
|
|
export default class RoleListCommand extends BaseCommand { |
10 |
|
|
supportsInteractions: boolean = true; |
11 |
|
|
|
12 |
|
|
constructor() { |
13 |
|
|
super('rolelist', 'information', []); |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
17 |
|
|
let role: Role | null = null; |
18 |
|
|
|
19 |
|
|
if (options.isInteraction) { |
20 |
|
|
if (options.options.getRole('role')) |
21 |
|
|
role = <Role> options.options.getRole('role'); |
22 |
|
|
} |
23 |
|
|
else { |
24 |
|
|
if (options.args[0]) |
25 |
|
|
try { |
26 |
|
|
role = <Role> await getRole(<Message> msg, options); |
27 |
|
|
|
28 |
|
|
if (!role) { |
29 |
|
|
throw new Error(); |
30 |
|
|
} |
31 |
|
|
} |
32 |
|
|
catch (e) { |
33 |
|
|
console.log(e); |
34 |
|
|
|
35 |
|
|
await msg.reply({ |
36 |
|
|
embeds: [ |
37 |
|
|
new MessageEmbed() |
38 |
|
|
.setColor('#f14a60') |
39 |
|
|
.setDescription('Failed to fetch role info. Maybe invalid role ID?') |
40 |
|
|
] |
41 |
|
|
}); |
42 |
|
|
|
43 |
|
|
return; |
44 |
|
|
} |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
if (!role) { |
48 |
|
|
const roles = await msg.guild!.roles.cache.toJSON(); |
49 |
|
|
let str = ``; |
50 |
|
|
|
51 |
|
|
for await (const role of roles) { |
52 |
|
|
if (role.id === msg.guild!.id) |
53 |
|
|
continue; |
54 |
|
|
|
55 |
rakin |
72 |
str += `${role.name} - ${role.id} - ${role.members.size} Members - ${role.hexColor}\n`; |
56 |
rakin |
60 |
} |
57 |
|
|
|
58 |
|
|
await msg.reply({ |
59 |
rakin |
72 |
content: "**Role List**:\n\n```" + str + '```' |
60 |
rakin |
60 |
}); |
61 |
|
|
} |
62 |
|
|
else { |
63 |
|
|
await msg.reply({ |
64 |
|
|
embeds: [ |
65 |
|
|
new MessageEmbed() |
66 |
|
|
.setAuthor({ |
67 |
|
|
name: `Role Information` |
68 |
|
|
}) |
69 |
|
|
.setColor(role.hexColor) |
70 |
|
|
.addFields([ |
71 |
|
|
{ |
72 |
|
|
name: 'Name', |
73 |
|
|
value: role.name |
74 |
|
|
}, |
75 |
|
|
{ |
76 |
|
|
name: 'Color', |
77 |
|
|
value: role.hexColor |
78 |
|
|
}, |
79 |
|
|
{ |
80 |
|
|
name: 'Members', |
81 |
|
|
value: role.members.size + '' |
82 |
|
|
}, |
83 |
|
|
{ |
84 |
|
|
name: 'Bot Role', |
85 |
|
|
value: role.members.size === 1 && role.members.first()?.user.bot ? 'Yes' : 'No' |
86 |
|
|
} |
87 |
|
|
]) |
88 |
|
|
] |
89 |
|
|
}); |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
} |