Add /roleshop list and /roleshop buy using MEE6 coins, with an editable list of roles and prices in settings and three starter prices (100, 500, 1000); the admin chooses the roles. /roleshop list posts a Components V2 card: a container with a heading, then one section per role with its name and price and a Buy button beside it, paginated with Previous/Next when the roles do not fit under 40 components. A Buy click answers the buyer privately.
Role Shop lets members buy roles using MEE6 coins.
/roleshop list posts the shop as one card: each role with its price and a Buy button beside it (10 roles a page, with Previous/Next past that). A click buys the role and answers the buyer privately./roleshop buy purchases a role by name.Setup contains an editable list of up to 25 roles, with three starter prices: 100, 500 and 1,000 coins. Select a real server role for each row, or remove unused rows. Prices and the catalogue can be changed without editing code.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
Purchase roles with your MEE6 coins!
@Bronze ๐ฐ 100 coins
@Silver ๐ฐ 500 coins
@Gold ๐ฐ 1000 coins
Click Buy, or use /roleshop buy to purchase a role
You have 180 coins.
You purchased @Bronze for 100 coins.
80 coins
// Role shop using MEE6 Economy coins
mee6.settings({
items: {
type: 'list',
label: 'Roles for sale',
maxItems: 25,
fields: {
role_id: { type: 'role', label: 'Role', required: true, sample: 'Member' },
price: { type: 'integer', label: 'Price (coins)', required: true, default: 100 },
},
default: [{ price: 100 }, { price: 500 }, { price: 1000 }],
sample: [
{ role_id: 'Bronze', price: 100 },
{ role_id: 'Silver', price: 500 },
{ role_id: 'Gold', price: 1000 },
],
},
});
interface ShopItem {
role_id: string | null;
price: number;
}
const BLUE = '#3498db';
// A role with its Buy button is 3 components: 10 a page keeps the card under Discord's 40.
const PER_PAGE = 10;
// Build the shop inventory from settings
function getShopItems(ctx: any): ShopItem[] {
return ((ctx.settings.items ?? []) as ShopItem[]).filter((item) => item.role_id && item.price >= 0);
}
/** The shop card: one line per role, its price and a Buy button beside it, 10 roles a page */
async function shopCard(items: ShopItem[], page: number): Promise<MessagePayload> {
const pages = Math.max(1, Math.ceil(items.length / PER_PAGE));
const current = Math.min(Math.max(page, 0), pages - 1);
// Get role names for display
const roles = await mee6.listRoles();
const roleMap = new Map(roles.map((r) => [r.id, r]));
const blocks: LayoutBlock[] = [{ type: 'text', text: '## ๐ Role Shop\nPurchase roles with your MEE6 coins!' }];
for (const item of items.slice(current * PER_PAGE, (current + 1) * PER_PAGE)) {
const role = roleMap.get(item.role_id!);
blocks.push({
type: 'section',
text: `**${role ? `@${role.name}` : 'Unknown Role'}**\n๐ฐ ${item.price} coins`,
button: { label: 'Buy', style: 'primary', customId: `roleshop:buy:${item.role_id}` },
});
}
blocks.push({ type: 'separator' });
const pageNote = pages > 1 ? ` ยท Page ${current + 1}/${pages}` : '';
blocks.push({ type: 'text', text: `-# Click Buy, or use /roleshop buy to purchase a role${pageNote}` });
if (pages > 1) {
blocks.push({
type: 'buttons',
buttons: [
{
label: 'Previous',
style: 'secondary',
customId: `roleshop:page:${current - 1}`,
disabled: current === 0,
},
{
label: 'Next',
style: 'secondary',
customId: `roleshop:page:${current + 1}`,
disabled: current === pages - 1,
},
],
});
}
return { layout: [{ type: 'container', color: BLUE, blocks }] };
}
mee6.command('roleshop list', { description: 'View available roles to purchase' }, async (ctx) => {
const items = getShopItems(ctx);
if (items.length === 0) {
await ctx.reply('The shop is not configured yet. Ask an admin to set up roles and prices in the dashboard.');
return;
}
await ctx.reply(await shopCard(items, 0));
});
/**
* Buy a role for the member: from /roleshop buy, answered as before, or from
* a Buy button on the shop card, answered to the buyer alone.
*/
async function purchase(ctx: Context, targetRoleId: string, privately: boolean): Promise<void> {
const answer = (payload: MessagePayload | string) =>
ctx.reply(
!privately
? payload
: typeof payload === 'string'
? { content: payload, ephemeral: true }
: { ...payload, ephemeral: true }
);
const items = getShopItems(ctx);
// Check if the role is in the shop
const shopItem = items.find((item) => item.role_id === targetRoleId);
if (!shopItem) {
await answer('โ That role is not available in the shop. Use `/roleshop list` to see available roles.');
return;
}
// Check if they already have the role
if (ctx.author.roles.includes(targetRoleId)) {
await answer('You already have this role!');
return;
}
// Check balance
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < shopItem.price) {
await answer(`โ Not enough coins! You have **${balance.coins}** coins but need **${shopItem.price}** coins.`);
return;
}
// Process purchase
try {
await mee6.economy.remove(ctx.author.id, shopItem.price);
await mee6.addRole(ctx.author.id, targetRoleId);
const roles = await mee6.listRoles();
const roleName = roles.find((r) => r.id === targetRoleId)?.name || 'Unknown Role';
await answer({
embed: {
title: 'โ
Purchase Successful!',
description: `You purchased **@${roleName}** for **${shopItem.price}** coins.`,
color: '#2ecc71',
fields: [{ name: 'Remaining Balance', value: `${balance.coins - shopItem.price} coins`, inline: true }],
},
});
} catch (error) {
// If role assignment failed, refund
await mee6.economy.add(ctx.author.id, shopItem.price);
await answer('โ Failed to assign the role. Your coins have been refunded.');
}
}
mee6.command(
'roleshop buy',
{
description: 'Purchase a role from the shop',
options: [{ name: 'role', type: 'role', description: 'The role to purchase', required: true }],
},
async (ctx) => {
await purchase(ctx, ctx.option<string>('role'), false);
}
);
// The shop card's buttons: Buy beside each role, Previous/Next between pages
mee6.on('button', async (ctx) => {
const id = ctx.customId ?? '';
if (id.startsWith('roleshop:buy:')) {
await purchase(ctx, id.slice('roleshop:buy:'.length), true);
} else if (id.startsWith('roleshop:page:')) {
const items = getShopItems(ctx);
if (items.length === 0) {
await ctx.editOriginal({ layout: [{ type: 'text', text: 'The shop is not configured yet.' }] });
return;
}
await ctx.editOriginal(await shopCard(items, parseInt(id.slice('roleshop:page:'.length)) || 0));
}
});