Build an inventory: /loot gives a random item from a list in the code with a category (weapon, armor, potion), and /inventory shows what the member owns with a select menu to show one category at a time, editing the message in place
Find random items with /loot and view your collection with /inventory. Use the dropdown menu to filter by category (weapons, armor, potions) or view everything at once.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
You found a Dagger! 🗡️
Weapon
1
You found a Iron Sword! ⚔️
Weapon
1
You found a Magic Staff! 🔮
Weapon
1
You found a Wooden Bow! 🏹
Weapon
1
You found a Invisibility Potion! 👻
Potion
1
You found a Iron Helmet! ⛑️
Armor
1
You found a Magic Staff! 🔮
Weapon
1
🔮 Magic Staff × 1 🏹 Wooden Bow × 1 ⛑️ Iron Helmet × 1 👻 Invisibility Potion × 1
// Item inventory with loot drops and category filtering
type ItemCategory = 'weapon' | 'armor' | 'potion';
interface Item {
name: string;
category: ItemCategory;
emoji: string;
}
// The loot table
const ITEMS: Item[] = [
// Weapons
{ name: 'Iron Sword', category: 'weapon', emoji: '⚔️' },
{ name: 'Steel Axe', category: 'weapon', emoji: '🪓' },
{ name: 'Magic Staff', category: 'weapon', emoji: '🔮' },
{ name: 'Wooden Bow', category: 'weapon', emoji: '🏹' },
{ name: 'Dagger', category: 'weapon', emoji: '🗡️' },
// Armor
{ name: 'Iron Helmet', category: 'armor', emoji: '⛑️' },
{ name: 'Leather Chestplate', category: 'armor', emoji: '🦺' },
{ name: 'Steel Shield', category: 'armor', emoji: '🛡️' },
{ name: 'Chain Boots', category: 'armor', emoji: '🥾' },
{ name: 'Magic Cloak', category: 'armor', emoji: '🧥' },
// Potions
{ name: 'Health Potion', category: 'potion', emoji: '❤️' },
{ name: 'Mana Potion', category: 'potion', emoji: '💙' },
{ name: 'Speed Potion', category: 'potion', emoji: '⚡' },
{ name: 'Strength Potion', category: 'potion', emoji: '💪' },
{ name: 'Invisibility Potion', category: 'potion', emoji: '👻' },
];
/** Get a random item from the loot table */
function randomItem(): Item {
return ITEMS[Math.floor(Math.random() * ITEMS.length)];
}
/** Format inventory items by category */
function formatInventory(inventory: Record<string, number>, category?: ItemCategory): string {
const items = ITEMS.filter((item) => !category || item.category === category);
const lines: string[] = [];
for (const item of items) {
const count = inventory[item.name] || 0;
if (count > 0) {
lines.push(`${item.emoji} **${item.name}** × ${count}`);
}
}
return lines.length > 0 ? lines.join('\n') : '_No items in this category_';
}
/** Count total items in inventory */
function countItems(inventory: Record<string, number>): number {
return Object.values(inventory).reduce((sum, count) => sum + count, 0);
}
mee6.command('loot', { description: 'Find a random item!' }, async (ctx) => {
const item = randomItem();
const m = mee6.store.member(ctx.author.id);
// Get current inventory
const inventory = await m.get<Record<string, number>>('inventory', {});
// Add the item
inventory[item.name] = (inventory[item.name] || 0) + 1;
await m.set('inventory', inventory);
await ctx.reply({
embed: {
title: '🎁 Loot Found!',
description: `You found a **${item.name}**! ${item.emoji}`,
color: '#FFD700',
fields: [
{
name: 'Category',
value: item.category.charAt(0).toUpperCase() + item.category.slice(1),
inline: true,
},
{
name: 'Total in Inventory',
value: `${inventory[item.name]}`,
inline: true,
},
],
},
});
});
mee6.command('inventory', { description: 'View your items' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const inventory = await m.get<Record<string, number>>('inventory', {});
const totalItems = countItems(inventory);
if (totalItems === 0) {
await ctx.reply({
content: 'Your inventory is empty! Use `/loot` to find some items.',
ephemeral: true,
});
return;
}
// Show all items by default
await ctx.reply({
embed: {
title: '🎒 Your Inventory',
description: formatInventory(inventory),
color: '#5865F2',
footer: { text: `Total items: ${totalItems}` },
},
selects: [
{
customId: 'category_filter',
placeholder: 'Filter by category...',
options: [
{ label: 'All Items', value: 'all', emoji: '🎒' },
{ label: 'Weapons', value: 'weapon', emoji: '⚔️' },
{ label: 'Armor', value: 'armor', emoji: '🛡️' },
{ label: 'Potions', value: 'potion', emoji: '🧪' },
],
},
],
});
});
mee6.on('select', async (ctx) => {
if (ctx.customId !== 'category_filter') return;
const m = mee6.store.member(ctx.author.id);
const inventory = await m.get<Record<string, number>>('inventory', {});
const totalItems = countItems(inventory);
const selected = ctx.values[0];
const category = selected === 'all' ? undefined : (selected as ItemCategory);
const title = category
? `🎒 Your Inventory — ${category.charAt(0).toUpperCase() + category.slice(1)}s`
: '🎒 Your Inventory';
await ctx.editOriginal({
embed: {
title,
description: formatInventory(inventory, category),
color: '#5865F2',
footer: { text: `Total items: ${totalItems}` },
},
});
});