Build a /daily-xp command with a once-a-day XP reward
A daily XP reward system that members can claim once every 24 hours.
Usage:
/daily-xp โ Claim your daily XP reward (50 XP by default)Features:
Settings:
Made by MEE6. Remix it to get a copy of your own and change anything you like.
You received 50 XP!
Level 4
870 XP
1 days
You received 50 XP!
Level 7
2650 XP
1 days
You received 50 XP!
Level 5
1500 XP
1 days
You've already claimed your daily reward!
Come back in 24h 0m
You received 50 XP!
Level 4
920 XP
2 days
// Daily XP reward command
// Members can claim once every 24 hours
mee6.settings({
xp_amount: {
type: 'integer',
label: 'Daily XP reward amount (1 to 100,000)',
default: 50,
sample: 50,
},
});
const MAX_XP = 100000; // what one call moves at most
mee6.command(
'daily-xp',
{
description: 'Claim your daily XP reward',
},
async (ctx) => {
const xpAmount = ctx.settings.xp_amount ?? 50;
if (xpAmount < 1 || xpAmount > MAX_XP) {
await ctx.reply(
`โ ๏ธ The daily reward must be between 1 and ${MAX_XP} XP. An admin needs to change it in the dashboard.`
);
return;
}
const m = mee6.store.member(ctx.author.id);
// Check cooldown (24 hours = 86400 seconds)
const lastClaim = await m.get<number>('daily_last_claim', 0);
const now = Math.floor(Date.now() / 1000);
const cooldown = 86400; // 24 hours
if (now - lastClaim < cooldown) {
const remaining = cooldown - (now - lastClaim);
const hours = Math.floor(remaining / 3600);
const minutes = Math.floor((remaining % 3600) / 60);
await ctx.reply({
embed: {
title: 'โฐ Daily Reward',
description: `You've already claimed your daily reward!\n\nCome back in **${hours}h ${minutes}m**`,
color: '#e74c3c',
},
});
return;
}
// Give XP and update cooldown
const result = await mee6.xp.give(ctx.author.id, xpAmount);
await m.set('daily_last_claim', now);
// Track total claims
await m.incr('daily_total_claims', 1);
const totalClaims = await m.get<number>('daily_total_claims', 1);
await ctx.reply({
embed: {
title: '๐ Daily Reward Claimed!',
description: `You received **${xpAmount} XP**!`,
color: '#2ecc71',
fields: [
{
name: 'Current Level',
value: `Level ${result.level}`,
inline: true,
},
{
name: 'Total XP',
value: `${result.xp} XP`,
inline: true,
},
{
name: 'Streak',
value: `${totalClaims} days`,
inline: true,
},
],
footer: {
text: 'Come back tomorrow for another reward!',
},
},
});
if (result.leveledUp) {
await ctx.send(ctx.channelId, `๐ ${ctx.author.mention} leveled up to **Level ${result.level}**!`);
}
}
);