/crate opens a lootbox bought with 100 coins and drops an item by rarity from a table in settings, /inventory lists what you own, and /craft combines three common items into one rare Make the common, rare and legendary item pools editable lists with the existing items as defaults; handle empty pools without charging for nothing.
A lootbox and crafting system integrated with MEE6 Economy. Spend 100 coins to open a crate and receive random items by rarity. Collect items in your inventory and craft three common items into one rare item to build your collection.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
Common Herbs
Common Wooden Sword
Common Small Potion
You crafted 3 common items into:
✨ Magic Ring
Legendary Celestial Armor
Common Flint
You need 100 coins to open a crate. You have 80 coins.
You need 100 coins to open a crate. You have 95 coins.
// Loot & Craft — Open lootboxes and craft items from your collection
// Item pools by rarity
const COMMON_ITEMS = [
'Wooden Sword',
'Leather Boots',
'Iron Ore',
'Cloth',
'Herbs',
'Small Potion',
'Rope',
'Flint',
'Feather',
'Bone',
];
const RARE_ITEMS = [
'Steel Sword',
'Chain Mail',
'Magic Ring',
'Enchanted Gem',
'Ancient Coin',
'Dragon Scale',
'Crystal Shard',
'Mystic Scroll',
'Silver Amulet',
];
const LEGENDARY_ITEMS = [
'Legendary Blade',
'Phoenix Feather',
'Crown of Kings',
'Staff of Power',
'Dragon Heart',
'Celestial Armor',
];
mee6.settings({
common_items: {
type: 'list',
label: 'Common items',
maxItems: 100,
fields: { name: { type: 'string', label: 'Name', required: true } },
default: COMMON_ITEMS.map((name) => ({ name })),
},
rare_items: {
type: 'list',
label: 'Rare items',
maxItems: 100,
fields: { name: { type: 'string', label: 'Name', required: true } },
default: RARE_ITEMS.map((name) => ({ name })),
},
legendary_items: {
type: 'list',
label: 'Legendary items',
maxItems: 100,
fields: { name: { type: 'string', label: 'Name', required: true } },
default: LEGENDARY_ITEMS.map((name) => ({ name })),
},
});
const CRATE_COST = 100;
// Drop rates: 70% common, 25% rare, 5% legendary. The first three crates a
// member opens are always common — the material for a first craft.
function rollItem(
opened: number,
COMMON_ITEMS: string[],
RARE_ITEMS: string[],
LEGENDARY_ITEMS: string[]
): { item: string; rarity: string } {
const pools = [
{ items: COMMON_ITEMS, rarity: 'Common', weight: 70 },
{ items: RARE_ITEMS, rarity: 'Rare', weight: 25 },
{ items: LEGENDARY_ITEMS, rarity: 'Legendary', weight: 5 },
].filter((pool) => pool.items.length);
if (!COMMON_ITEMS.length || !RARE_ITEMS.length || !LEGENDARY_ITEMS.length) {
let roll = Math.random() * pools.reduce((sum, pool) => sum + pool.weight, 0);
let selected = pools[pools.length - 1];
for (const pool of pools) {
roll -= pool.weight;
if (roll <= 0) {
selected = pool;
break;
}
}
return { item: selected.items[Math.floor(Math.random() * selected.items.length)], rarity: selected.rarity };
}
const roll = opened < 3 ? 0 : Math.random() * 100;
if (roll < 70) {
return {
item: COMMON_ITEMS[Math.floor(Math.random() * COMMON_ITEMS.length)],
rarity: 'Common',
};
} else if (roll < 95) {
return {
item: RARE_ITEMS[Math.floor(Math.random() * RARE_ITEMS.length)],
rarity: 'Rare',
};
} else {
return {
item: LEGENDARY_ITEMS[Math.floor(Math.random() * LEGENDARY_ITEMS.length)],
rarity: 'Legendary',
};
}
}
// /crate — Open a lootbox
mee6.command(
'crate',
{
description: 'Open a crate for 100 coins and receive a random item',
ephemeral: false,
},
async (ctx) => {
const COMMON_ITEMS = (ctx.settings.common_items as { name: string }[]).map((row) => row.name);
const RARE_ITEMS = (ctx.settings.rare_items as { name: string }[]).map((row) => row.name);
const LEGENDARY_ITEMS = (ctx.settings.legendary_items as { name: string }[]).map((row) => row.name);
// Check balance
const balance = await mee6.economy.balance(ctx.author.id);
if (balance.coins < CRATE_COST) {
await ctx.reply({
embed: {
title: '🔒 Insufficient Funds',
description: `You need ${CRATE_COST} coins to open a crate. You have ${balance.coins} coins.`,
color: '#e74c3c',
},
});
return;
}
if (!COMMON_ITEMS.length && !RARE_ITEMS.length && !LEGENDARY_ITEMS.length) {
await ctx.reply('No loot configured. Add items in settings.');
return;
}
// Deduct cost
await mee6.economy.remove(ctx.author.id, CRATE_COST);
// Roll for item
const m = mee6.store.member(ctx.author.id);
const opened = await m.get<number>('opened', 0);
const { item, rarity } = rollItem(opened, COMMON_ITEMS, RARE_ITEMS, LEGENDARY_ITEMS);
// Add to inventory
const inventory = await m.get<Record<string, number>>('inventory', {});
inventory[item] = (inventory[item] || 0) + 1;
await m.set('inventory', inventory);
await m.set('opened', opened + 1);
// Color by rarity
const color = rarity === 'Common' ? '#95a5a6' : rarity === 'Rare' ? '#9b59b6' : '#f39c12';
const emoji = rarity === 'Common' ? '📦' : rarity === 'Rare' ? '✨' : '🌟';
await ctx.reply({
embed: {
title: `${emoji} Crate Opened!`,
description: `**${rarity}**\n${item}`,
color,
footer: { text: `${balance.coins - CRATE_COST} coins remaining` },
},
});
}
);
// /inventory — View your items
mee6.command(
'inventory',
{
description: 'View your collected items',
ephemeral: true,
},
async (ctx) => {
const COMMON_ITEMS = (ctx.settings.common_items as { name: string }[]).map((row) => row.name);
const RARE_ITEMS = (ctx.settings.rare_items as { name: string }[]).map((row) => row.name);
const LEGENDARY_ITEMS = (ctx.settings.legendary_items as { name: string }[]).map((row) => row.name);
const m = mee6.store.member(ctx.author.id);
const inventory = await m.get<Record<string, number>>('inventory', {});
if (Object.keys(inventory).length === 0) {
await ctx.reply({
embed: {
title: '🎒 Inventory',
description: 'Your inventory is empty. Use `/crate` to open a lootbox!',
color: '#95a5a6',
},
});
return;
}
// Sort items by rarity and name
const sorted = Object.entries(inventory).sort((a, b) => {
const rarityA = LEGENDARY_ITEMS.includes(a[0]) ? 0 : RARE_ITEMS.includes(a[0]) ? 1 : 2;
const rarityB = LEGENDARY_ITEMS.includes(b[0]) ? 0 : RARE_ITEMS.includes(b[0]) ? 1 : 2;
if (rarityA !== rarityB) return rarityA - rarityB;
return a[0].localeCompare(b[0]);
});
// Build field list
const fields = [];
let currentRarity = '';
let currentItems: string[] = [];
for (const [item, count] of sorted) {
const rarity = LEGENDARY_ITEMS.includes(item)
? '🌟 Legendary'
: RARE_ITEMS.includes(item)
? '✨ Rare'
: '📦 Common';
if (rarity !== currentRarity) {
if (currentItems.length > 0) {
fields.push({ name: currentRarity, value: currentItems.join('\n'), inline: false });
}
currentRarity = rarity;
currentItems = [];
}
currentItems.push(`${item} ×${count}`);
}
if (currentItems.length > 0) {
fields.push({ name: currentRarity, value: currentItems.join('\n'), inline: false });
}
await ctx.reply({
embed: {
title: `🎒 ${ctx.author.displayName}'s Inventory`,
description: `Total items: ${Object.values(inventory).reduce((a, b) => a + b, 0)}`,
fields,
color: '#3498db',
},
});
}
);
// /craft — Combine three common items into one rare
mee6.command(
'craft',
{
description: 'Craft three common items into one rare item',
},
async (ctx) => {
const COMMON_ITEMS = (ctx.settings.common_items as { name: string }[]).map((row) => row.name);
const RARE_ITEMS = (ctx.settings.rare_items as { name: string }[]).map((row) => row.name);
const LEGENDARY_ITEMS = (ctx.settings.legendary_items as { name: string }[]).map((row) => row.name);
const m = mee6.store.member(ctx.author.id);
const inventory = await m.get<Record<string, number>>('inventory', {});
// Count common items
let totalCommons = 0;
const commonsOwned: string[] = [];
for (const [item, count] of Object.entries(inventory)) {
if (COMMON_ITEMS.includes(item)) {
totalCommons += count;
commonsOwned.push(item);
}
}
if (totalCommons < 3) {
await ctx.reply({
embed: {
title: '⚒️ Crafting Failed',
description: `You need at least 3 common items to craft. You have ${totalCommons}.`,
color: '#e74c3c',
},
});
return;
}
if (!RARE_ITEMS.length) {
await ctx.reply('No rare crafting rewards configured.');
return;
}
// Remove 3 common items (prioritize duplicates)
let removed = 0;
for (const item of commonsOwned) {
while (inventory[item] > 0 && removed < 3) {
inventory[item]--;
if (inventory[item] === 0) delete inventory[item];
removed++;
}
if (removed === 3) break;
}
// Give a random rare item
const rareItem = RARE_ITEMS[Math.floor(Math.random() * RARE_ITEMS.length)];
inventory[rareItem] = (inventory[rareItem] || 0) + 1;
await m.set('inventory', inventory);
await ctx.reply({
embed: {
title: '⚒️ Crafting Complete!',
description: `You crafted 3 common items into:\n\n✨ **${rareItem}**`,
color: '#9b59b6',
},
});
}
);