Build a ticket queue on private threads: /ticket open creates one with the member and the @Staff role, /claim marks it yours, /assign hands it to another staff member and pings them, /escalate adds the @Admin role and pins a summary, /close archives it, and /ticket stats shows how many tickets each staff member claimed and closed this month
A comprehensive ticket queue system using private threads. Members open tickets with /ticket open, staff can /claim them, /assign to other staff, /escalate to admins (which pings them and pins a summary), and /close to archive. /ticket stats shows monthly claim and close counts per staff member.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
This is the start of the #tickets channel.
// Ticket Queue — private thread-based support system
mee6.settings({
ticket_channel: {
type: 'channel',
label: 'Ticket channel (where threads are created)',
required: true,
sample: 'tickets',
},
staff_role: {
type: 'role',
label: 'Staff role (can claim tickets)',
required: true,
sample: 'Staff',
},
admin_role: {
type: 'role',
label: 'Admin role (for escalations)',
required: true,
sample: 'Admin',
},
});
/** The month's counters live on each staff member: one `incr` per claim
* or close, and the leaderboard is a `memberTop` — never a walk over every
* ticket key, which a busy month would push past a run's budget. */
function month(): string {
return new Date().toISOString().slice(0, 7); // YYYY-MM
}
async function countClaim(userId: string): Promise<void> {
await mee6.store.member(userId).incr(`claimed_${month()}`, 1);
}
async function countClose(userId: string): Promise<void> {
await mee6.store.member(userId).incr(`closed_${month()}`, 1);
}
mee6.command(
'ticket open',
{
description: 'Open a support ticket',
options: [{ name: 'reason', type: 'string', description: 'What do you need help with?', required: true }],
},
async (ctx) => {
const channelId = ctx.settings.ticket_channel;
const staffRoleId = ctx.settings.staff_role;
if (!channelId || !staffRoleId) {
await ctx.reply('Ticket system not configured — an admin needs to set the ticket channel and staff role.');
return;
}
const reason = ctx.option<string>('reason');
// Create a private thread
const thread = await mee6.createThread(channelId, `Ticket: ${ctx.author.username}`, {
private: true,
autoArchiveMinutes: 10080, // 1 week
});
// Store ticket metadata
await mee6.store.set(
`ticket_${thread.threadId}`,
{
openedBy: ctx.author.id,
openedAt: Date.now(),
reason,
status: 'open',
},
{ ttl: 2592000 } // 30 days
);
// Post initial message in the thread
await ctx.send(thread.threadId, {
content: `<@&${staffRoleId}> New ticket opened by ${ctx.author.mention}`,
// Notifies the staff role even when the server keeps it closed to pings
ping: [staffRoleId],
embed: {
title: '🎫 Support Ticket',
description: reason,
color: '#5865f2',
fields: [
{ name: 'Status', value: '🟡 Open', inline: true },
{ name: 'Opened by', value: ctx.author.mention, inline: true },
],
footer: { text: 'Use /claim to take this ticket' },
},
});
await ctx.reply({
content: `✅ Ticket created! Head to <#${thread.threadId}> to discuss with staff.`,
ephemeral: true,
});
}
);
mee6.command('claim', { description: 'Claim the current ticket', ephemeral: true }, async (ctx) => {
const channel = await mee6.getChannel(ctx.channelId);
if (!channel || channel.type !== 'thread') {
await ctx.reply('This command only works in ticket threads.');
return;
}
const staffRoleId = ctx.settings.staff_role;
if (!staffRoleId) {
await ctx.reply('Staff role not configured.');
return;
}
if (!ctx.author.roles.includes(staffRoleId)) {
await ctx.reply('Only staff members can claim tickets.');
return;
}
const ticket = await mee6.store.get<{
openedBy: string;
openedAt: number;
reason: string;
status: string;
claimedBy?: string;
}>(`ticket_${ctx.channelId}`);
if (!ticket) {
await ctx.reply('This thread is not a tracked ticket.');
return;
}
if (ticket.claimedBy) {
const claimer = await mee6.getMember(ticket.claimedBy);
await ctx.reply(`This ticket is already claimed by ${claimer?.mention || 'someone else'}.`);
return;
}
// Mark as claimed
ticket.claimedBy = ctx.author.id;
ticket.claimedAt = Date.now();
ticket.status = 'claimed';
await mee6.store.set(`ticket_${ctx.channelId}`, ticket, { ttl: 2592000 });
await countClaim(ctx.author.id);
await ctx.send(ctx.channelId, {
embed: {
title: '✅ Ticket Claimed',
description: `${ctx.author.mention} is now handling this ticket.`,
color: '#57f287',
},
});
await ctx.reply('You claimed this ticket.');
});
mee6.command(
'assign',
{
description: 'Assign the ticket to another staff member',
options: [{ name: 'staff', type: 'user', description: 'Staff member to assign to', required: true }],
ephemeral: true,
},
async (ctx) => {
const channel = await mee6.getChannel(ctx.channelId);
if (!channel || channel.type !== 'thread') {
await ctx.reply('This command only works in ticket threads.');
return;
}
const staffRoleId = ctx.settings.staff_role;
if (!staffRoleId) {
await ctx.reply('Staff role not configured.');
return;
}
if (!ctx.author.roles.includes(staffRoleId)) {
await ctx.reply('Only staff members can assign tickets.');
return;
}
const ticket = await mee6.store.get<{
openedBy: string;
openedAt: number;
reason: string;
status: string;
claimedBy?: string;
}>(`ticket_${ctx.channelId}`);
if (!ticket) {
await ctx.reply('This thread is not a tracked ticket.');
return;
}
const targetUserId = ctx.option<string>('staff');
const targetMember = await mee6.getMember(targetUserId);
if (!targetMember) {
await ctx.reply('Could not find that user.');
return;
}
if (!targetMember.roles.includes(staffRoleId)) {
await ctx.reply('You can only assign tickets to staff members.');
return;
}
// Update assignment
ticket.claimedBy = targetUserId;
ticket.claimedAt = Date.now();
ticket.status = 'claimed';
await mee6.store.set(`ticket_${ctx.channelId}`, ticket, { ttl: 2592000 });
await countClaim(targetUserId);
await ctx.send(ctx.channelId, {
content: targetMember.mention,
embed: {
title: '🔁 Ticket Assigned',
description: `${ctx.author.mention} assigned this ticket to ${targetMember.mention}.`,
color: '#5865f2',
},
});
await ctx.reply(`Assigned to ${targetMember.displayName}.`);
}
);
mee6.command('escalate', { description: 'Escalate the ticket to admins', ephemeral: true }, async (ctx) => {
const channel = await mee6.getChannel(ctx.channelId);
if (!channel || channel.type !== 'thread') {
await ctx.reply('This command only works in ticket threads.');
return;
}
const staffRoleId = ctx.settings.staff_role;
const adminRoleId = ctx.settings.admin_role;
if (!staffRoleId || !adminRoleId) {
await ctx.reply('Roles not configured.');
return;
}
if (!ctx.author.roles.includes(staffRoleId)) {
await ctx.reply('Only staff members can escalate tickets.');
return;
}
const ticket = await mee6.store.get<{
openedBy: string;
openedAt: number;
reason: string;
status: string;
claimedBy?: string;
escalated?: boolean;
}>(`ticket_${ctx.channelId}`);
if (!ticket) {
await ctx.reply('This thread is not a tracked ticket.');
return;
}
if (ticket.escalated) {
await ctx.reply('This ticket is already escalated.');
return;
}
// Mark as escalated
ticket.escalated = true;
ticket.status = 'escalated';
await mee6.store.set(`ticket_${ctx.channelId}`, ticket, { ttl: 2592000 });
const opener = await mee6.getMember(ticket.openedBy);
const claimer = ticket.claimedBy ? await mee6.getMember(ticket.claimedBy) : null;
// Post escalation summary and pin it
const sent = await ctx.send(ctx.channelId, {
content: `<@&${adminRoleId}>`,
ping: [adminRoleId],
embed: {
title: '⚠️ Ticket Escalated',
description: ticket.reason,
color: '#ed4245',
fields: [
{ name: 'Opened by', value: opener?.mention || 'Unknown', inline: true },
{ name: 'Claimed by', value: claimer?.mention || 'Unclaimed', inline: true },
{ name: 'Escalated by', value: ctx.author.mention, inline: true },
],
footer: { text: 'Admin attention required' },
},
});
await mee6.pin(sent.channelId, sent.messageId);
await ctx.reply('Ticket escalated to admins and summary pinned.');
});
mee6.command('close', { description: 'Close the current ticket', ephemeral: true }, async (ctx) => {
const channel = await mee6.getChannel(ctx.channelId);
if (!channel || channel.type !== 'thread') {
await ctx.reply('This command only works in ticket threads.');
return;
}
const staffRoleId = ctx.settings.staff_role;
if (!staffRoleId) {
await ctx.reply('Staff role not configured.');
return;
}
if (!ctx.author.roles.includes(staffRoleId)) {
await ctx.reply('Only staff members can close tickets.');
return;
}
const ticket = await mee6.store.get<{
openedBy: string;
openedAt: number;
reason: string;
status: string;
claimedBy?: string;
closedBy?: string;
closedAt?: number;
}>(`ticket_${ctx.channelId}`);
if (!ticket) {
await ctx.reply('This thread is not a tracked ticket.');
return;
}
if (ticket.status === 'closed') {
await ctx.reply('This ticket is already closed.');
return;
}
// Mark as closed
ticket.closedBy = ctx.author.id;
ticket.closedAt = Date.now();
ticket.status = 'closed';
await mee6.store.set(`ticket_${ctx.channelId}`, ticket, { ttl: 2592000 });
await countClose(ctx.author.id);
await ctx.send(ctx.channelId, {
embed: {
title: '🔒 Ticket Closed',
description: `Closed by ${ctx.author.mention}`,
color: '#95a5a6',
footer: { text: 'This thread will now be archived' },
},
});
await ctx.reply('Ticket closed.');
// Archive and lock the thread
await mee6.archiveThread(ctx.channelId);
});
mee6.command('ticket stats', { description: 'View ticket statistics for this month', ephemeral: true }, async (ctx) => {
const staffRoleId = ctx.settings.staff_role;
if (!staffRoleId) {
await ctx.reply('Staff role not configured.');
return;
}
if (!ctx.author.roles.includes(staffRoleId)) {
await ctx.reply('Only staff members can view ticket stats.');
return;
}
const closedTop = await mee6.store.memberTop(`closed_${month()}`, 10);
const claimedTop = await mee6.store.memberTop(`claimed_${month()}`, 10);
const ids = [...new Set([...closedTop, ...claimedTop].map((e) => e.user_id))].slice(0, 10);
if (ids.length === 0) {
await ctx.reply('No ticket activity this month.');
return;
}
// Build leaderboard
const entries = [];
for (const userId of ids) {
const member = await mee6.getMember(userId);
entries.push({
name: member?.displayName || 'Unknown',
claimed: claimedTop.find((e) => e.user_id === userId)?.value ?? 0,
closed: closedTop.find((e) => e.user_id === userId)?.value ?? 0,
});
}
entries.sort((a, b) => b.closed - a.closed || b.claimed - a.claimed);
const fields = entries.slice(0, 10).map((e, i) => ({
name: `${i + 1}. ${e.name}`,
value: `📥 ${e.claimed} claimed • ✅ ${e.closed} closed`,
inline: false,
}));
await ctx.reply({
embed: {
title: '📊 Ticket Statistics (This Month)',
color: '#5865f2',
fields,
footer: { text: `Top ${Math.min(entries.length, 10)} staff members` },
},
});
});