When a member gains a role I choose in settings, prefix their nickname with a short tag for that role, and remove the tag when they lose the role; never touch the nickname of members the bot cannot manage
Automatically adds a customizable tag prefix to member nicknames when they gain a specific role, and removes it when they lose the role.
Setup:
[VIP])How it works:
Made by MEE6. Remix it to get a copy of your own and change anything you like.
// Role Tag Prefix — automatically add/remove nickname tags based on role
mee6.settings({
target_role: {
type: 'role',
label: 'Role to tag',
required: true,
sample: 'VIP',
},
tag: {
type: 'string',
label: 'Tag prefix (e.g. [VIP])',
default: '[VIP]',
sample: '[VIP]',
},
});
mee6.on('member_update', async (ctx) => {
const targetRoleId = ctx.settings.target_role;
const tag = ctx.settings.tag;
if (!targetRoleId) {
mee6.log('Target role not configured');
return;
}
if (!tag) {
mee6.log('Tag not configured');
return;
}
// Check if the target role was added or removed
const gainedRole = ctx.addedRoles.includes(targetRoleId);
const lostRole = ctx.removedRoles.includes(targetRoleId);
if (!gainedRole && !lostRole) {
return; // Not relevant to our target role
}
// Get current nickname (or display name if no nickname set)
const currentNick = ctx.author.displayName;
const tagWithSpace = `${tag} `;
try {
if (gainedRole) {
// Add tag if it's not already there
if (!currentNick.startsWith(tag)) {
const newNick = tagWithSpace + currentNick;
await mee6.setNickname(ctx.author.id, newNick);
mee6.log(`Added tag to ${ctx.author.username}: ${newNick}`);
}
} else if (lostRole) {
// Remove tag if it's there
if (currentNick.startsWith(tagWithSpace)) {
const newNick = currentNick.substring(tagWithSpace.length);
await mee6.setNickname(ctx.author.id, newNick || null);
mee6.log(`Removed tag from ${ctx.author.username}: ${newNick || '(reset)'}`);
}
}
} catch (error) {
// Silently fail if we can't manage this member (higher role, owner, permissions)
mee6.log(`Could not update nickname for ${ctx.author.username}: ${error}`);
}
});