Add /rolepanel which posts a self-assignable role panel as a Components V2 layout: one container with a ## heading and an intro, then one section per role with its emoji, name and description, and a Get / Remove button on the right that toggles the role for whoever presses it and answers privately ("You now have @Role" / "Removed @Role"). The roles and their descriptions come from a list setting (role, emoji, description; at most 12, so the card stays under Discord's 40 components). Only members with a staff role from settings can run it; running it again edits the existing panel in place instead of posting a new one.
A role panel built with Discord's new message layouts: one card with a heading, then each role on a line of its own with its emoji, its description and a Get / Remove button on the right. Members press it to take the role and press it again to give it back; the answer is private, so the channel stays clean.
How to use:
/rolepanel to post the card/rolepanel again after changing the list: the same card is updated in place/rolepanel open to everyone in its command permissions — the panel's buttons follow the same rules, and the command already checks the staff role itselfMade by MEE6. Remix it to get a copy of your own and change anything you like.
Press Get / Remove beside a role to add it, and again to take it off. Only you see the answer.
📣 Announcements Get pinged when we post server news.
🎉 Events Game nights, contests and giveaways.
🎮 Gamer Find teammates and join squad nights.
🎨 Artist Share your art and join the monthly challenge.
4 roles · press again to remove
Posted the role panel in #roles with 4 roles.
Updated the role panel in #roles with 4 roles.
// Role panel: one card of self-assignable roles, each with its description and
// a Get / Remove button beside it. The roles come from the settings list, and
// running /rolepanel again refreshes the same card in place.
interface PanelRole {
role: string | null;
emoji: string | null;
description: string | null;
}
interface PanelRef {
channelId: string;
messageId: string;
}
// Discord fits 40 components in one message. The card, its heading, a divider
// and the footer take four; each role takes three (section, text, button).
const MAX_ROLES = 12;
const BUTTON_PREFIX = 'rolepanel:';
const DEFAULT_COLOR = '#5865F2';
mee6.settings({
staff_role: {
type: 'role',
label: 'Who can post the panel',
description:
'Members with this role, and the server owner, can run /rolepanel. Every member can use the buttons of the panel it posts.',
required: true,
sample: 'Staff',
},
channel: {
type: 'channel',
label: 'Panel channel',
description: 'Where the role panel lives.',
required: true,
sample: 'roles',
},
title: { type: 'string', label: 'Heading', default: 'Pick your roles' },
intro: {
type: 'string',
label: 'Intro',
default: 'Press **Get / Remove** beside a role to add it, and again to take it off. Only you see the answer.',
},
color: { type: 'string', label: 'Card colour', description: 'A hex colour such as #5865F2.', default: DEFAULT_COLOR },
roles: {
type: 'list',
label: 'Roles on the panel',
description: 'Up to 12 roles: Discord fits 40 components in a message, and each role takes three.',
required: true,
maxItems: MAX_ROLES,
fields: {
role: { type: 'role', label: 'Role', required: true },
emoji: { type: 'emoji', label: 'Emoji' },
description: { type: 'string', label: 'Description' },
},
default: [
{ emoji: '📣', description: 'Get pinged when we post server news.' },
{ emoji: '🎉', description: 'Game nights, contests and giveaways.' },
{ emoji: '🎮', description: 'Find teammates and join squad nights.' },
{ emoji: '🎨', description: 'Share your art and join the monthly challenge.' },
],
sample: [
{ role: 'Announcements', emoji: '📣', description: 'Get pinged when we post server news.' },
{ role: 'Events', emoji: '🎉', description: 'Game nights, contests and giveaways.' },
{ role: 'Gamer', emoji: '🎮', description: 'Find teammates and join squad nights.' },
{ role: 'Artist', emoji: '🎨', description: 'Share your art and join the monthly challenge.' },
],
},
});
function cardColor(raw: unknown): string {
const value = String(raw ?? '').trim();
return /^#?[0-9a-f]{6}$/i.test(value) ? (value.startsWith('#') ? value : `#${value}`) : DEFAULT_COLOR;
}
function panelLayout(
settings: Record<string, unknown>,
rows: { entry: PanelRole; id: string; name: string }[]
): LayoutBlock[] {
const title = String(settings.title ?? '').trim() || 'Pick your roles';
const intro = String(settings.intro ?? '').trim();
const blocks: LayoutBlock[] = [
{ type: 'text', text: intro ? `## ${title}\n${intro}` : `## ${title}` },
{ type: 'separator' },
];
for (const { entry, id, name } of rows) {
// The role's name in bold rather than its mention: a mentionable role
// would be pinged every time the panel is posted or refreshed.
const head = `${entry.emoji ? `${entry.emoji} ` : ''}**${name}**`;
const description = String(entry.description ?? '').trim();
blocks.push({
type: 'section',
text: description ? `${head}\n${description}` : head,
button: { label: 'Get / Remove', style: 'secondary', customId: `${BUTTON_PREFIX}${id}` },
});
}
blocks.push({ type: 'text', text: `-# ${rows.length} role${rows.length === 1 ? '' : 's'} · press again to remove` });
return [{ type: 'container', color: cardColor(settings.color), blocks }];
}
mee6.command('rolepanel', { description: 'Post or refresh the role panel', ephemeral: true }, async (ctx) => {
const staff = ctx.settings.staff_role as string | null;
if (!staff) {
await ctx.reply('Choose who can post the panel in the dashboard settings first.');
return;
}
// The server owner may always post it, staff role or not
if (!ctx.author.roles.includes(staff) && ctx.author.id !== (await mee6.guild()).ownerId) {
await ctx.reply(`Only <@&${staff}> can post the role panel.`);
return;
}
const channelId = ctx.settings.channel as string | null;
if (!channelId) {
await ctx.reply('No panel channel is set yet — an admin can choose one in the dashboard.');
return;
}
const entries = ((ctx.settings.roles as PanelRole[]) ?? []).filter((entry) => entry.role);
const serverRoles = await mee6.listRoles();
const rows: { entry: PanelRole; id: string; name: string }[] = [];
const missing: string[] = [];
for (const entry of entries) {
const info = serverRoles.find((role) => role.id === entry.role);
// A bot's or the booster role is Discord's to give, never a member's.
if (!info || info.managed) missing.push(entry.role!);
else if (!rows.some((row) => row.id === info.id)) rows.push({ entry, id: info.id, name: info.name });
}
if (!rows.length) {
await ctx.reply('No roles to offer yet — add some under **Roles on the panel** in the dashboard.');
return;
}
const payload = { layout: panelLayout(ctx.settings, rows.slice(0, MAX_ROLES)) };
const saved = await mee6.store.get<PanelRef | null>('panel', null);
let verb = 'Posted';
let where: PanelRef | null = null;
if (saved && saved.channelId === channelId && (await mee6.getMessage(saved.channelId, saved.messageId))) {
// Same channel, panel still there: refresh it, so its link and its place stay.
await mee6.editMessage(saved.channelId, saved.messageId, payload);
verb = 'Updated';
where = saved;
} else {
if (saved && saved.channelId !== channelId) {
// The panel moved channel: the old card goes, rather than two panels disagreeing.
try {
await mee6.deleteMessage(saved.channelId, saved.messageId);
} catch {
mee6.log('the previous panel could not be deleted; it may already be gone');
}
}
const sent = await ctx.send(channelId, payload);
where = { channelId: sent.channelId, messageId: sent.messageId! };
await mee6.store.set('panel', where);
}
const notes: string[] = [];
if (missing.length) notes.push(`${missing.length} role(s) left out: deleted, or managed by Discord.`);
if (rows.length > MAX_ROLES) notes.push(`Only the first ${MAX_ROLES} roles fit on one card.`);
await ctx.reply(
[`${verb} the role panel in <#${where.channelId}> with ${Math.min(rows.length, MAX_ROLES)} roles.`, ...notes].join(
'\n'
)
);
});
mee6.on('button', async (ctx) => {
if (!ctx.customId.startsWith(BUTTON_PREFIX)) return;
const roleId = ctx.customId.slice(BUTTON_PREFIX.length);
const offered = ((ctx.settings.roles as PanelRole[]) ?? []).some((entry) => entry.role === roleId);
if (!offered) {
await ctx.reply({
content: 'That role is no longer on offer. An admin can refresh the panel with /rolepanel.',
ephemeral: true,
});
return;
}
const had = ctx.author.roles.includes(roleId);
try {
if (had) await ctx.removeRole(roleId);
else await ctx.addRole(roleId);
} catch {
await ctx.reply({
content: `I couldn't ${
had ? 'remove' : 'give you'
} <@&${roleId}>: MEE6's role must sit above it in Server Settings → Roles. Let an admin know.`,
ephemeral: true,
});
return;
}
await ctx.reply({
content: had ? `Removed <@&${roleId}>.` : `You now have <@&${roleId}>.`,
ephemeral: true,
});
});