1import {
2 ChatInputCommandInteraction,
3 EmbedBuilder,
4 SlashCommandBuilder,
5 Collection,
6} from 'discord.js'
7import { Command } from '@/types/bot'
8
9export default {
10 data: new SlashCommandBuilder()
11 .setName('roleinfo')
12 .setDescription('Get information about a role')
13 .addRoleOption((option) =>
14 option
15 .setName('role')
16 .setDescription('The role to get info about')
17 .setRequired(true),
18 ),
19
20 async execute(interaction: ChatInputCommandInteraction) {
21 const role = interaction.options.getRole('role', true)
22
23 let members = interaction.guild?.members.cache.filter((member) =>
24 member.roles.cache.has(role.id),
25 )
26
27 if (!members) {
28 members = new Collection()
29 }
30
31 const createdTimestamp = interaction.guild?.roles.cache.get(
32 role.id,
33 )?.createdTimestamp
34
35 const embed = new EmbedBuilder()
36 .setColor(role.color)
37 .setTitle(`Role Information: ${role.name}`)
38 .addFields(
39 { name: 'ID', value: role.id, inline: true },
40 {
41 name: 'Color',
42 value: `#${role.color.toString(16).padStart(6, '0')}`,
43 inline: true,
44 },
45 { name: 'Position', value: role.position.toString(), inline: true },
46 {
47 name: 'Mentionable',
48 value: role.mentionable ? 'Yes' : 'No',
49 inline: true,
50 },
51 { name: 'Hoisted', value: role.hoist ? 'Yes' : 'No', inline: true },
52 { name: 'Members', value: members.size.toString(), inline: true },
53 {
54 name: 'Created',
55 value: `<t:${Math.floor(createdTimestamp! / 1000)}:R>`,
56 inline: true,
57 },
58 )
59 .setTimestamp()
60
61 await interaction.reply({ embeds: [embed] })
62 },
63} as Command
64