Add /clockin and /clockout which track the time a member works, /hours which shows a member\'s total for the week, and a report of everyone\'s hours every Monday at 9am UTC in a channel I choose
Track work hours for your team with simple clock-in and clock-out commands.
Commands:
/clockin — Start tracking your work time/clockout — Stop tracking and see your shift duration/hours [member] — View total hours worked this weekAutomated Reports: Every Monday at 9am UTC, a report of everyone's hours from the previous week is posted to your chosen channel.
Setup: Configure the weekly report channel in the dashboard settings.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
✅ Clocked in at 07:43 AM. Have a productive shift!
✅ Clocked out at 10:43 AM. Shift duration: 3h 0m This week's total: 3.0h
✅ Clocked in at 10:43 AM. Have a productive shift!
✅ Clocked out at 12:13 PM. Shift duration: 1h 30m This week's total: 1.5h
@Alex's hours for this week
3.0h
// Work Hours Tracker — clock in/out, view weekly hours, automated Monday reports
mee6.settings({
report_channel: {
type: 'channel',
label: 'Weekly report channel',
required: true,
sample: 'timesheets',
},
});
// Clock in — record start time
mee6.command('clockin', { description: 'Clock in to start tracking work time' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const activeSession = await m.get<number>('clock_in_time');
if (activeSession) {
await ctx.reply('⏰ You are already clocked in! Use `/clockout` to end your shift.');
return;
}
const now = Date.now();
await m.set('clock_in_time', now);
await ctx.reply(`✅ Clocked in at <t:${Math.floor(now / 1000)}:t>. Have a productive shift!`);
});
// Clock out — calculate hours and add to weekly total
mee6.command('clockout', { description: 'Clock out to stop tracking work time' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const clockInTime = await m.get<number>('clock_in_time');
if (!clockInTime) {
await ctx.reply('⏰ You are not currently clocked in! Use `/clockin` to start a shift.');
return;
}
const now = Date.now();
const durationMs = now - clockInTime;
const hours = durationMs / (1000 * 60 * 60);
// Add to this week's total
const weekKey = getWeekKey();
const weeklyHours = await m.get<number>(weekKey, 0);
await m.set(weekKey, weeklyHours + hours);
// Clear active session
await m.delete('clock_in_time');
const hoursDisplay = formatDuration(durationMs);
await ctx.reply(
`✅ Clocked out at <t:${Math.floor(now / 1000)}:t>.\n` +
`**Shift duration:** ${hoursDisplay}\n` +
`**This week's total:** ${formatHours(weeklyHours + hours)}`
);
});
// View your hours for the current week
mee6.command(
'hours',
{
description: "View a member's work hours for this week",
options: [{ name: 'member', type: 'user', description: 'Member to check (defaults to you)' }],
},
async (ctx) => {
const targetId = ctx.option<string>('member') || ctx.author.id;
const m = mee6.store.member(targetId);
const weekKey = getWeekKey();
const hours = await m.get<number>(weekKey, 0);
const clockedIn = await m.get<number>('clock_in_time');
let status = '';
if (clockedIn && targetId === ctx.author.id) {
const elapsed = Date.now() - clockedIn;
status = `\n🟢 Currently clocked in (${formatDuration(elapsed)} so far)`;
} else if (clockedIn) {
status = '\n🟢 Currently clocked in';
}
await ctx.reply({
embed: {
title: '⏰ Work Hours',
description: `<@${targetId}>'s hours for this week`,
fields: [{ name: 'Total Hours', value: formatHours(hours), inline: true }],
color: '#5865F2',
footer: { text: `Week of ${getWeekStart()}` },
},
content: status || undefined,
});
}
);
// Scheduled report every Monday at 9am UTC
mee6.schedule.cron('weekly_report', '0 9 * * 1');
mee6.on('scheduled', async (ctx) => {
if (ctx.scheduleKey !== 'weekly_report') return;
const channelId = ctx.settings.report_channel;
if (!channelId) {
mee6.log('Weekly report: no channel configured');
return;
}
// Get top 25 members by hours worked last week
const lastWeekKey = getWeekKey(-1);
const leaderboard = await mee6.store.memberTop(lastWeekKey, 25);
if (leaderboard.length === 0) {
await ctx.send(channelId, {
embed: {
title: '📊 Weekly Work Hours Report',
description: 'No hours logged last week.',
color: '#99AAB5',
footer: { text: `Week of ${getWeekStart(-1)}` },
},
});
return;
}
// Format the leaderboard
const lines = await Promise.all(
leaderboard.map(async (entry, i) => {
const member = await mee6.getMember(entry.user_id);
const name = member ? member.displayName : 'Unknown';
return `${i + 1}. **${name}** — ${formatHours(entry.value as number)}`;
})
);
await ctx.send(channelId, {
embed: {
title: '📊 Weekly Work Hours Report',
description: lines.join('\n'),
color: '#5865F2',
footer: { text: `Week of ${getWeekStart(-1)}` },
},
});
});
// Helper: get the storage key for a given week (0 = current, -1 = last week, etc.)
function getWeekKey(offset = 0): string {
const now = new Date();
const monday = new Date(now);
monday.setUTCDate(now.getUTCDate() - ((now.getUTCDay() + 6) % 7) + offset * 7); // Monday of the week (a Sunday belongs to the week before)
monday.setUTCHours(0, 0, 0, 0);
return `hours_${monday.toISOString().slice(0, 10)}`;
}
// Helper: get the date of Monday for display
function getWeekStart(offset = 0): string {
const now = new Date();
const monday = new Date(now);
monday.setUTCDate(now.getUTCDate() - ((now.getUTCDay() + 6) % 7) + offset * 7);
monday.setUTCHours(0, 0, 0, 0);
return monday.toISOString().slice(0, 10);
}
// Helper: format hours as "X.Xh"
function formatHours(hours: number): string {
return `${hours.toFixed(1)}h`;
}
// Helper: format duration in ms as "Xh Ym"
function formatDuration(ms: number): string {
const totalMinutes = Math.floor(ms / (1000 * 60));
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
if (hours > 0) {
return `${hours}h ${minutes}m`;
}
return `${minutes}m`;
}