Skip to content

Instantly share code, notes, and snippets.

@LostLuma
Created June 1, 2021 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LostLuma/308b23bcf46265daca1042a95ee2ac7c to your computer and use it in GitHub Desktop.
Save LostLuma/308b23bcf46265daca1042a95ee2ac7c to your computer and use it in GitHub Desktop.
// Adds a `/pronouns` slash command to the server
// Configure the roles you would like to use here
// The record maps choice name -> Discord role ID
const PRONOUN_ROLES: Record<string, string> = {
'she/her': '823327679855591454',
'he/him': '823327736277106698',
'they/them': '823328487549042688'
};
const group = discord.interactions.commands.registerGroup({
name: 'pronouns',
description: 'Choose which pronoun roles you have in the server.'
});
group.register(
{
name: 'add',
description: 'Add a pronoun role to yourself.',
ackBehavior: discord.interactions.commands.AckBehavior.MANUAL,
options: (opts) => ({
pronoun: opts.string({
required: true,
description: 'The pronoun role to add.',
choices: Object.keys(PRONOUN_ROLES)
})
})
},
async (interaction, { pronoun }) => {
const roleId = PRONOUN_ROLES[pronoun];
if (!roleId) {
await interaction.respondEphemeral(
'Something unexpected went wrong. Please contact Blob Mail.'
);
return;
}
await interaction.member.addRole(roleId);
await interaction.respondEphemeral(
`You've been given the \`${pronoun}\` pronoun role.`
);
}
);
group.register(
{
name: 'remove',
description: 'Remove a pronoun role from yourself.',
ackBehavior: discord.interactions.commands.AckBehavior.MANUAL,
options: (opts) => ({
pronoun: opts.string({
required: true,
description: 'The pronoun role to remove.',
choices: Object.keys(PRONOUN_ROLES)
})
})
},
async (interaction, { pronoun }) => {
const roleId = PRONOUN_ROLES[pronoun];
if (!roleId) {
await interaction.respondEphemeral(
'Something unexpected went wrong. Please contact Blob Mail.'
);
return;
}
await interaction.member.removeRole(roleId);
await interaction.respondEphemeral(
`Your \`${pronoun}\` pronoun role has been removed.`
);
}
);
@3kh0
Copy link

3kh0 commented May 5, 2022

thank you for this script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment