Created
January 4, 2021 05:24
-
-
Save SpencerSharkey/8a9e7ac049bb8f52e64eb688adaace43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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