Add /giverole and /takerole, restricted to the @Staff role, that give or remove one of the roles I list in settings (three roles) from a member the moderator names, and log each change in a channel I choose
Restricted /giverole and /takerole commands that let staff members assign or remove three configurable roles from members. All changes are logged to a designated channel with timestamps and staff attribution.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
✅ Gave the Member role to @Jordan.
❌ You need the staff role to use this command.
✅ Removed the Member role from @Jordan.
// Role management commands for staff
mee6.settings({
staff_role: { type: 'role', label: 'Staff role (who can use these commands)', required: true, sample: 'Staff' },
role_1: { type: 'role', label: 'Manageable role #1', required: true, sample: 'Member' },
role_2: { type: 'role', label: 'Manageable role #2', required: true, sample: 'Active' },
role_3: { type: 'role', label: 'Manageable role #3', required: true, sample: 'Verified' },
log_channel: { type: 'channel', label: 'Log channel for role changes', required: true, sample: 'mod-logs' },
});
mee6.command(
'giverole',
{
description: 'Give a role to a member (staff only)',
options: [
{ name: 'member', type: 'user', description: 'Member to give the role to', required: true },
{ name: 'role', type: 'role', description: 'Which role to give (one of the three configured)', required: true },
],
},
async (ctx) => {
// Check staff permission
if (!ctx.settings.staff_role) {
await ctx.reply('No staff role is configured yet — an admin can set it in the dashboard.');
return;
}
if (!ctx.author.roles.includes(ctx.settings.staff_role)) {
await ctx.reply('❌ You need the staff role to use this command.');
return;
}
const memberId = ctx.option<string>('member');
const roleId = ctx.option<string>('role');
// Staff may only hand out the roles an admin listed in the settings.
const allowed = [ctx.settings.role_1, ctx.settings.role_2, ctx.settings.role_3].filter(Boolean);
if (!allowed.includes(roleId)) {
await ctx.reply(
`❌ <@&${roleId}> is not one of the roles staff may manage — an admin picks them in the dashboard.`
);
return;
}
// Get role name for logging
const roles = await mee6.listRoles();
const role = roles.find((r) => r.id === roleId);
const roleName = role ? role.name : roleId;
try {
await mee6.addRole(memberId, roleId);
await ctx.reply(`✅ Gave the **${roleName}** role to <@${memberId}>.`);
// Log the change
if (ctx.settings.log_channel) {
await ctx.send(ctx.settings.log_channel, {
embed: {
title: '📝 Role Added',
color: '#57F287',
fields: [
{ name: 'Member', value: `<@${memberId}>`, inline: true },
{ name: 'Role', value: `**${roleName}**`, inline: true },
{ name: 'By', value: `<@${ctx.author.id}>`, inline: true },
],
timestamp: new Date().toISOString(),
},
});
}
} catch (error) {
await ctx.reply(
`❌ Failed to add the role. Make sure I have the Manage Roles permission and a higher role than **${roleName}**.`
);
}
}
);
mee6.command(
'takerole',
{
description: 'Remove a role from a member (staff only)',
options: [
{ name: 'member', type: 'user', description: 'Member to remove the role from', required: true },
{ name: 'role', type: 'role', description: 'Which role to remove (one of the three configured)', required: true },
],
},
async (ctx) => {
// Check staff permission
if (!ctx.settings.staff_role) {
await ctx.reply('No staff role is configured yet — an admin can set it in the dashboard.');
return;
}
if (!ctx.author.roles.includes(ctx.settings.staff_role)) {
await ctx.reply('❌ You need the staff role to use this command.');
return;
}
const memberId = ctx.option<string>('member');
const roleId = ctx.option<string>('role');
// Staff may only hand out the roles an admin listed in the settings.
const allowed = [ctx.settings.role_1, ctx.settings.role_2, ctx.settings.role_3].filter(Boolean);
if (!allowed.includes(roleId)) {
await ctx.reply(
`❌ <@&${roleId}> is not one of the roles staff may manage — an admin picks them in the dashboard.`
);
return;
}
// Get role name for logging
const roles = await mee6.listRoles();
const role = roles.find((r) => r.id === roleId);
const roleName = role ? role.name : roleId;
try {
await mee6.removeRole(memberId, roleId);
await ctx.reply(`✅ Removed the **${roleName}** role from <@${memberId}>.`);
// Log the change
if (ctx.settings.log_channel) {
await ctx.send(ctx.settings.log_channel, {
embed: {
title: '📝 Role Removed',
color: '#ED4245',
fields: [
{ name: 'Member', value: `<@${memberId}>`, inline: true },
{ name: 'Role', value: `**${roleName}**`, inline: true },
{ name: 'By', value: `<@${ctx.author.id}>`, inline: true },
],
timestamp: new Date().toISOString(),
},
});
}
} catch (error) {
await ctx.reply(
`❌ Failed to remove the role. Make sure I have the Manage Roles permission and a higher role than **${roleName}**.`
);
}
}
);