62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { RoleCreateOptions, GuildMember, CommandInteraction, SlashCommandBuilder } from 'discord.js';
|
|
import { getRoleSeperator, pronouns } 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))
|
|
)
|
|
.setDefaultMemberPermissions(0)
|
|
.setDMPermission(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 seperator = await getRoleSeperator('color', member.guild);
|
|
if (!seperator) log.info('no color role seperator found');
|
|
|
|
const roleSettings: RoleCreateOptions = {
|
|
name: pronoun,
|
|
hoist: false,
|
|
mentionable: false,
|
|
permissions: 0n
|
|
};
|
|
if (seperator) {
|
|
roleSettings.position = seperator.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; |