Skip to content

Instantly share code, notes, and snippets.

@SpencerSharkey
Created January 4, 2021 05:24
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 SpencerSharkey/8a9e7ac049bb8f52e64eb688adaace43 to your computer and use it in GitHub Desktop.
Save SpencerSharkey/8a9e7ac049bb8f52e64eb688adaace43 to your computer and use it in GitHub Desktop.
interface UserRole {
name: string;
roleId: discord.Snowflake;
}
// list of roles to give out
const USER_ROLES: Array<UserRole> = [
{
name: 'Minecraft',
roleId: '647793990753714176'
},
{
name: 'Pet Owner',
roleId: '641506307848929290'
},
{
name: 'Music Head',
roleId: '413333688558944277'
},
{
name: 'Artist',
roleId: '389472408442109954'
},
{
name: 'Foodie',
roleId: '433081859736338454'
},
];
discord.interactions.commands.register(
{
name: 'role',
description: '🏷️ Gives or removes the selected role',
showSourceMessage: false,
options: (opts) => ({
role: opts.string({
description: "🏷️ The role you'd like to add or remove",
choices: USER_ROLES.map((c) => ({
name: c.name,
value: c.roleId
}))
})
})
},
async (interaction, { role }) => {
const { member } = interaction;
// important to validate the role id against the valid choices
if (!USER_ROLES.find((c) => c.roleId === role)) {
await interaction.respondEphemeral(
'Sorry, that is not a valid role choice. Please choose from one of the options!'
);
return;
}
if (member.roles.includes(role)) {
await member.removeRole(role);
await interaction.respondEphemeral(
`\n🥺 You already had the <@&${role}> role, so I removed it.`
);
} else {
await member.addRole(role);
await interaction.respondEphemeral(
`\n🥰 I granted you the <@&${role}> role!`
);
}
// const logChannel = await discord.getGuildTextChannel(LOGS_CHANNEL);
// if (logChannel) {
// await logChannel.sendMessage({
// content: `${interaction.member.toMention()} used \`/role\` <@&${role}>`,
// allowedMentions: {}
// });
// }
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment