/gather gives a random item so there is something to trade, /trade offers an item from your inventory to a member for one of theirs, they see both sides with Accept and Decline buttons only they can press, and the swap only happens if both still own their item at that moment
A simple trading system where members can gather random items from a pool of 10 different collectibles and offer trades to other members.
Commands:
/gather โ Find a random item and add it to your inventory/inventory โ View all the items you've collected/trade โ Propose a trade with another member: offer one of your items for one of theirsHow trading works: When you offer a trade, the other member sees an embed showing both sides of the exchange with Accept and Decline buttons. Only they can press the buttons. When they accept, the system checks that both members still have their items (preventing double-trades), then swaps them atomically. Trade offers expire after 5 minutes.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
โจ You found ๐ชจ Stone! You now have 1.
โจ You found ๐ชจ Stone! You now have 1.
โจ You found ๐ชต Wood! You now have 1.
โจ You found ๐พ Wheat! You now have 1.
๐ชจ Stone ร 1
๐พ Wheat ร 1 ๐ชจ Stone ร 1 ๐ชต Wood ร 1
โ Trade complete!
@You received ๐พ Wheat @Jordan received ๐ชจ Stone
๐ชจ Stone ร 2 ๐ชต Wood ร 1
// Trading system: gather random items, trade with other members
const ITEMS = [
'๐ชจ Stone',
'๐ชต Wood',
'๐พ Wheat',
'๐ฅ Carrot',
'๐ Fish',
'โ๏ธ Gear',
'๐ Diamond',
'๐ฎ Crystal',
'๐ Star',
'๐ Mushroom',
];
/** Whether a call was refused because the member has left the server. */
function hasLeft(err: unknown): boolean {
return String(err).includes('is not in this server');
}
function randomItem(): string {
return ITEMS[Math.floor(Math.random() * ITEMS.length)];
}
mee6.command('gather', { description: 'Find a random item' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const inv = await m.get<Record<string, number>>('inventory', {});
// The first finds follow the list โ a stone, then wood, then wheat โ so
// two newcomers have something to trade; luck after that.
const gathered = await m.get<number>('gathered', 0);
const item = gathered < 3 ? ITEMS[gathered] : randomItem();
inv[item] = (inv[item] || 0) + 1;
await m.set('inventory', inv);
await m.set('gathered', gathered + 1);
await ctx.reply(`โจ You found **${item}**! You now have **${inv[item]}**.`);
});
mee6.command('inventory', { description: 'View your items' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const inv = await m.get<Record<string, number>>('inventory', {});
if (Object.keys(inv).length === 0) {
await ctx.reply('Your inventory is empty. Use `/gather` to find items!');
return;
}
const lines = Object.entries(inv)
.sort(([a], [b]) => a.localeCompare(b))
.map(([item, count]) => `${item} ร **${count}**`);
await ctx.reply({
embed: {
title: '๐ Your Inventory',
description: lines.join('\n'),
color: 0x5865f2,
},
});
});
mee6.command(
'trade',
{
description: 'Offer a trade to another member',
options: [
{ name: 'member', type: 'user', description: 'Who to trade with', required: true },
{ name: 'your_item', type: 'string', description: 'Item you offer (e.g. ๐ชจ Stone)', required: true },
{ name: 'their_item', type: 'string', description: 'Item you want from them', required: true },
],
},
async (ctx) => {
const targetId = ctx.option<string>('member');
const yourItem = ctx.option<string>('your_item');
const theirItem = ctx.option<string>('their_item');
if (targetId === ctx.author.id) {
await ctx.reply('You cannot trade with yourself!');
return;
}
// Check proposer has the item
const yourInv = await mee6.store.member(ctx.author.id).get<Record<string, number>>('inventory', {});
if (!yourInv[yourItem] || yourInv[yourItem] < 1) {
await ctx.reply(`You don't have **${yourItem}** to trade.`);
return;
}
// Check target has their item
const theirInv = await mee6.store.member(targetId).get<Record<string, number>>('inventory', {});
if (!theirInv[theirItem] || theirInv[theirItem] < 1) {
await ctx.reply(`<@${targetId}> doesn't have **${theirItem}** to trade.`);
return;
}
const tradeId = String(await mee6.store.incr('trade_seq'));
await mee6.store.set(
`trade_${tradeId}`,
{
proposer: ctx.author.id,
target: targetId,
proposerItem: yourItem,
targetItem: theirItem,
},
{ ttl: 300 }
);
const sent = await ctx.reply({
content: `<@${targetId}>, <@${ctx.author.id}> wants to trade!`,
embed: {
title: '๐ค Trade Offer',
description: `<@${ctx.author.id}> offers **${yourItem}**\n<@${targetId}> gives **${theirItem}**`,
color: 0xf1c40f,
footer: { text: 'This offer expires in 5 minutes' },
},
buttons: [
{ label: 'Accept', customId: `trade_accept_${tradeId}`, style: 'success' },
{ label: 'Decline', customId: `trade_decline_${tradeId}`, style: 'danger' },
],
});
}
);
mee6.on('button', async (ctx) => {
if (ctx.customId.startsWith('trade_accept_')) {
const tradeId = ctx.customId.replace('trade_accept_', '');
const trade = await mee6.store.get<{
proposer: string;
target: string;
proposerItem: string;
targetItem: string;
}>(`trade_${tradeId}`);
if (!trade) {
await ctx.reply({ content: 'This trade has expired.', ephemeral: true });
return;
}
// Only the target can accept
if (ctx.author.id !== trade.target) {
await ctx.reply({ content: 'Only the person being offered the trade can accept it.', ephemeral: true });
return;
}
// Check both still have their items
const proposerM = mee6.store.member(trade.proposer);
const targetM = mee6.store.member(trade.target);
const proposerInv = await proposerM.get<Record<string, number>>('inventory', {});
const targetInv = await targetM.get<Record<string, number>>('inventory', {});
if (!proposerInv[trade.proposerItem] || proposerInv[trade.proposerItem] < 1) {
await ctx.reply({ content: 'Trade failed: the proposer no longer has that item.', ephemeral: true });
await ctx.editOriginal({ content: 'โ Trade cancelled (item no longer available)', buttons: [] });
await mee6.store.delete(`trade_${tradeId}`);
return;
}
if (!targetInv[trade.targetItem] || targetInv[trade.targetItem] < 1) {
await ctx.reply({ content: 'Trade failed: you no longer have that item.', ephemeral: true });
await ctx.editOriginal({ content: 'โ Trade cancelled (item no longer available)', buttons: [] });
await mee6.store.delete(`trade_${tradeId}`);
return;
}
// Execute the swap
proposerInv[trade.proposerItem] -= 1;
if (proposerInv[trade.proposerItem] === 0) delete proposerInv[trade.proposerItem];
proposerInv[trade.targetItem] = (proposerInv[trade.targetItem] || 0) + 1;
targetInv[trade.targetItem] -= 1;
if (targetInv[trade.targetItem] === 0) delete targetInv[trade.targetItem];
targetInv[trade.proposerItem] = (targetInv[trade.proposerItem] || 0) + 1;
// The proposer's side first: one who has left the server cannot receive
// anything, and the offer goes with them, nothing swapped
try {
await proposerM.set('inventory', proposerInv);
} catch (err) {
if (!hasLeft(err)) throw err;
await mee6.store.delete(`trade_${tradeId}`);
await ctx.editOriginal({ content: 'โ Trade cancelled (the proposer has left the server)', buttons: [] });
await ctx.reply({ content: 'Trade failed: the proposer has left the server.', ephemeral: true });
return;
}
await targetM.set('inventory', targetInv);
await mee6.store.delete(`trade_${tradeId}`);
await ctx.editOriginal({
content: `โ
Trade complete!`,
embed: {
title: '๐ค Trade Successful',
description: `<@${trade.proposer}> received **${trade.targetItem}**\n<@${trade.target}> received **${trade.proposerItem}**`,
color: 0x2ecc71,
},
buttons: [],
});
await ctx.reply({ content: 'โ
Trade accepted!', ephemeral: true });
}
if (ctx.customId.startsWith('trade_decline_')) {
const tradeId = ctx.customId.replace('trade_decline_', '');
const trade = await mee6.store.get<{
proposer: string;
target: string;
proposerItem: string;
targetItem: string;
}>(`trade_${tradeId}`);
if (!trade) {
await ctx.reply({ content: 'This trade has expired.', ephemeral: true });
return;
}
// Only the target can decline
if (ctx.author.id !== trade.target) {
await ctx.reply({ content: 'Only the person being offered the trade can decline it.', ephemeral: true });
return;
}
await mee6.store.delete(`trade_${tradeId}`);
await ctx.editOriginal({
content: 'โ Trade declined',
buttons: [],
});
await ctx.reply({ content: 'Trade declined.', ephemeral: true });
}
});