Community

Quick poll

Slash command + reactions

Asks a question via slash command, then adds ✅/❌ reactions — a lightweight poll without a database.

Based on discord.js — SlashCommandBuilder options

/poll

Sign up first

Source preview

import {
  Client,
  Events,
  GatewayIntentBits,
  REST,
  Routes,
  SlashCommandBuilder,
} from "discord.js";

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const commands = [
  new SlashCommandBuilder()
    .setName("poll")
    .setDescription("Create a quick yes/no poll")
    .addStringOption((o) =>
      o.setName("question").setDescription("Poll question").setRequired(true),
    ),
].map((c) => c.toJSON());

client.once(Events.ClientReady, async () => {
  const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN!);
  await rest.put(Routes.applicationCommands(client.user!.id), { body: commands });
});

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== "poll") return;
  const question = interaction.options.getString("question", true);
  await interaction.reply({
    content: `📊 **${question}**\nReact with ✅ or ❌`,
  });
  const msg = await interaction.fetchReply();
  await msg.react("✅");
  await msg.react("❌");
});

client.login(process.env.DISCORD_TOKEN);