Add /quickpoll which takes a question and up to five options separated by commas, posts a select menu where each member picks one, and edits the message with the live counts and percentages
Create interactive polls where members vote via select menu. The poll updates in real-time showing vote counts, percentages, and progress bars for each option. Members can change their vote at any time, and the results update automatically.
Usage: /quickpoll with a question and 2-5 options separated by commas
Features:
Made by MEE6. Remix it to get a copy of your own and change anything you like.
📊 What should we play this weekend?
Minecraft ██████░░░░ 2 votes (67%)
Valorant ███░░░░░░░ 1 vote (33%)
Among Us ░░░░░░░░░░ 0 votes (0%)
3 votes • Select below to vote
// Poll creation with live vote counts
interface PollData {
question: string;
options: string[];
votes: Record<string, string>; // userId -> option they picked
}
mee6.command(
'quickpoll',
{
description: 'Create a poll with up to 5 options',
options: [
{ name: 'question', type: 'string', description: 'The poll question', required: true },
{ name: 'options', type: 'string', description: 'Options separated by commas (2-5)', required: true },
],
},
async (ctx) => {
const question = ctx.option<string>('question');
const optionsRaw = ctx.option<string>('options');
// Parse and validate options
const options = optionsRaw
.split(',')
.map((o) => o.trim())
.filter((o) => o.length > 0);
if (options.length < 2) {
await ctx.reply('Please provide at least 2 options separated by commas.');
return;
}
if (options.length > 5) {
await ctx.reply('Maximum 5 options allowed.');
return;
}
// Check for duplicates
const uniqueOptions = new Set(options);
if (uniqueOptions.size !== options.length) {
await ctx.reply('Options must be unique.');
return;
}
const pollData: PollData = {
question,
options,
votes: {},
};
const sent = await ctx.reply({
content: formatPoll(pollData),
selects: [
{
customId: 'poll_vote',
placeholder: 'Choose your answer…',
options: options.map((opt) => ({ label: opt, value: opt })),
},
],
});
await mee6.store.set(`poll_${sent.messageId}`, pollData, { ttl: 604800 }); // 7 days
}
);
mee6.on('select', async (ctx) => {
if (ctx.customId !== 'poll_vote') return;
const pollData = await mee6.store.get<PollData>(`poll_${ctx.message.id}`);
if (!pollData) {
await ctx.reply({ content: 'This poll has expired.', ephemeral: true });
return;
}
// ctx.values is an array of selected values
const choice = ctx.values && ctx.values.length > 0 ? ctx.values[0] : null;
if (!choice) {
await ctx.reply({ content: 'No option selected.', ephemeral: true });
return;
}
// Record the vote (replaces previous vote if any)
pollData.votes[ctx.author.id] = choice;
await mee6.store.set(`poll_${ctx.message.id}`, pollData, { ttl: 604800 });
// Update the message with new counts
await ctx.editOriginal({ content: formatPoll(pollData) });
await ctx.reply({ content: `You voted for: **${choice}**`, ephemeral: true });
});
/** Format the poll with live counts and percentages */
function formatPoll(poll: PollData): string {
const totalVotes = Object.keys(poll.votes).length;
let result = `📊 **${poll.question}**\n\n`;
if (totalVotes === 0) {
result += poll.options.map((opt) => `**${opt}**: 0 votes (0%)`).join('\n');
result += `\n\n_No votes yet • ${poll.options.length} options_`;
} else {
// Count votes per option
const counts: Record<string, number> = {};
for (const opt of poll.options) {
counts[opt] = 0;
}
for (const vote of Object.values(poll.votes)) {
counts[vote] = (counts[vote] || 0) + 1;
}
// Format each option with bar and percentage
for (const opt of poll.options) {
const count = counts[opt];
const pct = Math.round((count / totalVotes) * 100);
const barLength = Math.floor(pct / 10);
const bar = '█'.repeat(barLength) + '░'.repeat(10 - barLength);
result += `**${opt}**\n${bar} ${count} vote${count === 1 ? '' : 's'} (${pct}%)\n\n`;
}
result += `_${totalVotes} vote${totalVotes === 1 ? '' : 's'} • Select below to vote_`;
}
return result;
}