Add a /pay command that transfers coins from the caller to another member, refusing the transfer if they cannot afford it
Transfer coins between members using the /pay command.
/pay @member amount — Send coins to another member from your balance.
The command validates that:
Uses the server's MEE6 Economy plugin currency.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
@You paid @Jordan 50 coins.
130 coins
@Sam paid @You 25 coins.
70 coins
❌ Insufficient funds. You have 390 coins but need 500.
❌ You cannot pay yourself!
// Pay command - transfer coins between members
mee6.command(
'pay',
{
description: 'Transfer coins to another member',
options: [
{ name: 'recipient', type: 'user', description: 'Who to pay', required: true },
{ name: 'amount', type: 'integer', description: 'How many coins to send', required: true },
],
},
async (ctx) => {
const recipientId = ctx.option<string>('recipient');
const amount = ctx.option<number>('amount');
// Validation
if (recipientId === ctx.author.id) {
await ctx.reply('❌ You cannot pay yourself!');
return;
}
if (amount <= 0) {
await ctx.reply('❌ Amount must be positive.');
return;
}
// Only a member can be paid
if (!(await mee6.getMember(recipientId))) {
await ctx.reply(`❌ <@${recipientId}> is not in this server.`);
return;
}
// Check if sender has enough coins
const senderBalance = await mee6.economy.balance(ctx.author.id);
if (senderBalance.coins < amount) {
await ctx.reply(`❌ Insufficient funds. You have **${senderBalance.coins}** coins but need **${amount}**.`);
return;
}
// Perform the transfer: the sender is charged first, and refunded if the
// recipient cannot be paid, so no failure creates or loses coins
await mee6.economy.remove(ctx.author.id, amount);
try {
await mee6.economy.add(recipientId, amount);
} catch (err) {
await mee6.economy.add(ctx.author.id, amount);
throw err;
}
await ctx.reply({
embed: {
title: '💸 Payment Sent',
description: `${ctx.author.mention} paid <@${recipientId}> **${amount}** coins.`,
color: '#2ecc71',
fields: [{ name: 'Your new balance', value: `${senderBalance.coins - amount} coins`, inline: true }],
},
});
}
);