Custom Commands docsCustom CommandsDocs

Search docs

Find a page, function or guide

HomeSupportDashboard

Getting started

  • Introduction
  • Your first command
  • How a command runs
  • Variables in replies
  • Text commands
  • Events
  • Using Slushy

Guides

  • Welcome messages
  • Role menus
  • Auto moderation
  • Social alerts
  • Moderation commands
  • Levels and XP
  • Economy and coins
  • Ticket system
  • Giveaways
  • Poll
  • Button game
  • Reminders

Concepts

  • Buttons and menus
  • Forms
  • Saving data
  • Permissions and cooldowns
  • Limits and premium
  • Common mistakes

API reference

  • Response
  • Messages
  • Embeds
  • Members and roles
  • Channels
  • Storage
  • Checks
  • Views
  • Components
  • Modals
  • Interactions
  • Paginators
  • Web and files
  • Scheduling
  • Server events and polls
  • Time
  • Waiting
  • Utilities
  • Objects
  • Event variables

Examples

  • /8ball
  • /coinflip
  • /avatar
  • /serverinfo
  • /rank
  • /remind

Guides

View .md

Poll

Make a /poll command that posts a real Discord poll, or a quick vote with buttons.

You will make /poll. Members run it with a question and some answers. The bot posts a poll that everyone can vote on.

There are two ways to do it:

WayBest for
Discord pollMost polls. Discord counts the votes and shows the result bar. Lasts from 1 hour to 32 days.
Button voteA quick yes/no vote that ends after a few minutes.

Discord poll#

1. Create the command#

Open Create → Slash Command and switch to Advanced at the top of the form.

FieldValue
Command Namepoll
DescriptionStart a poll

Under Behavior, turn on Only the user sees the reply. The poll itself is public. Only the "Poll posted" note is private.

2. Add the arguments#

Under Arguments, add three:

TypeNameRequiredDescription
TextquestionYesWhat to ask
TextanswersYesAnswers, split by commas
IntegerhoursNoHow long it stays open

3. Add the code#

Open Pre-hook and paste:

python
choices = [a.strip() for a in answers.split(",") if a.strip()]
if len(choices) < 2:
    set_error("Give at least two answers, split by commas.")

await create_poll(question, choices, duration=hours or 24)
set_content("Poll posted!")

Leave the Content / Reply Message box empty. set_content writes the reply.

4. Try it#

Save, then run:

text
/poll question: Pizza or burgers? answers: Pizza, Burgers, Both

Discord's poll limits

  • Up to 10 answers. Extra answers are dropped.
  • Each answer can be up to 55 characters. The question can be up to 300.
  • duration is in hours, from 1 to 768 (32 days). The default is 24.

Let members pick more than one#

Add multiselect=True:

python
await create_poll(question, choices, duration=hours or 24, multiselect=True)

Post it in another channel#

Add channel=. It takes a channel, its ID or its name:

python
await create_poll(question, choices, channel="announcements")

Button vote#

This version puts Yes and No buttons on the reply. Each button shows its count. A member can change their vote. Each member counts once.

Make a new slash command named vote with one Text argument named question. Leave Only the user sees the reply off, so everyone can see the buttons.

Pre-hook#

python
class Vote(View):
    def __init__(self):
        self.votes = {}

    async def cast(self, interaction, choice):
        await defer(interaction, action="update")
        self.votes[str(interaction.user.id)] = choice
        yes = len([v for v in self.votes.values() if v == "yes"])
        no = len(self.votes) - yes
        self.update_component("yes", label=f"Yes ({yes})")
        self.update_component("no", label=f"No ({no})")
        # Edit through the newest click, so the edit never expires.
        self.interaction = interaction
        await self.update_view()

    @button(label="Yes (0)", style="success", custom_id="yes")
    async def yes(self, interaction, component):
        await self.cast(interaction, "yes")

    @button(label="No (0)", style="danger", custom_id="no")
    async def no(self, interaction, component):
        await self.cast(interaction, "no")

view = Vote()
view.interaction = interaction
set_view(view)
set_content(f"**{question}**\nClick to vote.")

Post-hook#

The post-hook runs when the vote ends. Voting ends after 3 minutes with no new votes. Each new vote starts the 3 minutes again.

python
yes = len([v for v in view.votes.values() if v == "yes"])
no = len(view.votes) - yes
await respond_interaction(
    view.interaction,
    content=f"**{question}**\nVoting closed. Yes: {yes} · No: {no}",
)

respond_interaction changes the text and removes the buttons.

Tip

Need a vote that stays open for hours or days? Use the Discord poll above. Buttons on a command reply are for short votes.

Learn more#

  • Buttons and menus explains how a View works.
  • Server events and polls lists every argument of create_poll.
  • Views lists update_component, update_view and the other View tools.
PreviousGiveawaysNext Button game

On this page

  • Discord poll
  • 1. Create the command
  • 2. Add the arguments
  • 3. Add the code
  • 4. Try it
  • Let members pick more than one
  • Post it in another channel
  • Button vote
  • Pre-hook
  • Post-hook
  • Learn more
Custom CommandsCustom Commands

The #1 Custom Commands Discord bot — build commands, events and databases with zero boilerplate.

Join the support server

Product

  • Overview
  • Why us?
  • Premium
  • Template shop

Features

  • AI Agent
  • Reaction roles
  • Welcome messages
  • Embed builder
  • Social alerts
  • Custom bot

Resources

  • Docs
  • Blog
  • Support
  • Dashboard

Company

  • Privacy
  • Terms
  • Contact
contact@ccbot.app

2 Frederick Street, London, WC1X 0ND

Payments secured by Stripe

© WEiRDSOFT LTD. All rights reserved.

Custom Commands