52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
const { SlashCommandBuilder } = require('discord.js');
|
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
|
const log = new DebugBuilder("server", "give-role");
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('give-role')
|
|
.setDescription('Use this command to give a role you have to another member.')
|
|
.addUserOption(option =>
|
|
option.setName('user')
|
|
.setDescription('The user you wish to give the role to ')
|
|
.setRequired(true))
|
|
.addRoleOption(option =>
|
|
option.setName('role')
|
|
.setDescription('The role you wish to give the selected user')
|
|
.setRequired(true)),
|
|
example: "give-role",
|
|
isPrivileged: false,
|
|
requiresTokens: false,
|
|
defaultTokenUsage: 0,
|
|
deferInitialReply: true,
|
|
/*async autocomplete(interaction) {
|
|
const focusedValue = interaction.options.getFocused();
|
|
},*/
|
|
async execute(interaction) {
|
|
try{
|
|
// The role to give to the user
|
|
const selectedRole = interaction.options.getRole('role');
|
|
|
|
// The user who should be given the role
|
|
var selectedUser = interaction.options.getUser("user");
|
|
selectedUser = interaction.guild.members.cache.get(selectedUser.id);
|
|
|
|
|
|
// The user who initiated the command
|
|
const initUser = interaction.member;
|
|
|
|
log.DEBUG("Give Role DEBUG: ", initUser, selectedRole, selectedUser);
|
|
|
|
// Check if the user has the role selected
|
|
if (!initUser.roles.cache.find(role => role.name === selectedRole.name)) return await interaction.editReply(`Sorry ${initUser}, you don't have the group ${selectedRole} and thus you cannot give it to ${selectedUser}`);
|
|
|
|
// Give the selected user the role and let both the user and the initiator know
|
|
await selectedUser.roles.add(selectedRole);
|
|
|
|
return await interaction.editReply(`Ok ${initUser}, ${selectedUser} has been given the ${selectedRole} role!`)
|
|
}catch(err){
|
|
log.ERROR(err)
|
|
//await interaction.reply(err.toString());
|
|
}
|
|
}
|
|
}; |