Add command for self-role management
parent
126ae1bc38
commit
1864565977
@ -0,0 +1,54 @@
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('role')
|
||||
.setDescription('Apply a role to yourself, or remove yourself from it. Toggley')
|
||||
.addStringOption(option =>
|
||||
option.setName("role")
|
||||
.setDescription('The role you wish to join')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: 'Smite', value: '843092235016208404' },
|
||||
{ name: 'Factorio', value: '995806023094894642' },
|
||||
{ name: 'Minecraft', value: '854460008292286494' },
|
||||
)),
|
||||
async execute(interaction) {
|
||||
|
||||
// Get role id from the choice
|
||||
let roleId = interaction.options.getString('role');
|
||||
// Then get the role itself
|
||||
let role = interaction.guild.roles.cache.get(roleId);
|
||||
|
||||
// If the role doesn't exist, then exit
|
||||
if (!role){
|
||||
await interaction.reply('Role not found');
|
||||
console.log('Role not found ' + roleId);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Check if the user is already in role.
|
||||
// If they are we want to remove them
|
||||
if (interaction.member.roles.cache.has(roleId)) {
|
||||
console.log('in role already');
|
||||
var reply = 'You\'ve been removed from the role ' + interaction.options.getString('role');
|
||||
// Remove user from role
|
||||
interaction.member.roles.remove(role);
|
||||
}
|
||||
else {
|
||||
var reply = 'You\'ve been added to the role ' + interaction.options.getString('role');
|
||||
// Add user to role
|
||||
interaction.member.roles.add(role);
|
||||
}
|
||||
|
||||
// Return message to the user in Discord channel
|
||||
// Ephemeral only shows to the person that called the command
|
||||
await interaction.reply({
|
||||
content: reply,
|
||||
ephemeral: true
|
||||
});
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue