import { RoleCreateOptions, GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js'; import { pronouns, PRONOUN_ROLE_SEPERATOR } from '../lib/assignableRoles'; import * as log from '../lib/log'; import { Command } from '../types/index'; function extendOption(t: string) { return {name: t, value: t}; } export default { data: new SlashCommandBuilder() .setName('pronoun') .setDescription('Give yourself a pronoun or two.') .addStringOption((option) => option .setName('pronoun') .setDescription('Pronoun to add. If you already have a pronoun, you can specify it to remove it.') .setRequired(true) .setChoices(...Array.from(pronouns.values()).map(extendOption)) ) .setDefaultPermission(false), execute: async (interaction: CommandInteraction) => { if (!interaction.isChatInputCommand()) return; const member = interaction.member! as GuildMember; await interaction.deferReply({ ephemeral: true }); const pronoun = interaction.options.getString('pronoun', true); const pronounRoleSeperator = await member.guild.roles.fetch(PRONOUN_ROLE_SEPERATOR); if (!pronounRoleSeperator) log.error('no pronoun role seperator found?!?!'); const roleSettings: RoleCreateOptions = { name: pronoun, hoist: false, mentionable: false, permissions: 0n }; if (pronounRoleSeperator) { roleSettings.position = pronounRoleSeperator.position; } const pronounRole = member.guild.roles.cache.find(role => role.name === pronoun) || await member.guild.roles.create(roleSettings); if (member.roles.cache.has(pronounRole.id)) { await member.roles.remove(pronounRole); interaction.followUp({ content: `Removed \`${pronoun}\` from your roles.` }); } else { await member.roles.add(pronounRole); interaction.followUp({ content: `Added \`${pronoun}\` to your roles.` }); } } } satisfies Command;