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

API reference

View .md

Waiting

Pause a command until someone sends a message, reacts, clicks or submits a form.

wait_for lets a command ask a question and wait for the answer, all in one run.

Write await in front of wait_for.

Tip

For buttons and menus, use a View instead. It handles clicks for you and is shorter.

wait_for#

Waits for the next event that passes your check. Returns the event.

python
await wait_for(
    event_name,
    timeout=None,
    check=None,
    reset_timeout_on_check_fail=False,
    raise_error=False,
)
ArgumentWhat it does
event_nameWhat to wait for. See the list below.
timeoutSeconds to wait. None waits with no end.
checkA function that gets each event and returns True for the one you want. predicate is another name for it.
reset_timeout_on_check_failTrue starts the timer again after each event that fails the check.
raise_errorTrue stops with an error on timeout. Otherwise you get None.
event_nameWaits for
"message"A new message
"message_delete"A deleted message
"reaction"Any reaction added or removed
"reaction_add"A reaction added
"reaction_remove"A reaction removed
"interaction"Any click, menu pick or form submit
"modal_submit"A form (modal) submitted
"clock"A clock you dispatched

Always add a check

wait_for hears events from every server the bot is in. Always check the channel and the person. Always set a timeout, so the command does not wait forever.

Example: a guessing game

python
# pre-hook
secret = randomNumber(1, 10)
set_content("I picked a number from 1 to 10. Guess it in the chat!")
python
# post-hook
def same_person(evt):
    return evt.channel_id == channel.id and evt.author_id == user.id

evt = await wait_for("message", timeout=30, check=same_person)
if evt is None:
    send_message(channel, "Time is up!")
elif evt.content.strip() == str(secret):
    send_message(channel, f"Yes! It was {secret}.")
else:
    send_message(channel, f"No, it was {secret}.")

The question is in the reply, so the wait goes in the post-hook. The post-hook runs after the reply is sent. See How commands run.

What you get back#

You get an event, not the message itself. The message ID is evt.message_id. There is no evt.id.

event_nameAttributes on the event
"message"content, author, author_id, member, message, message_id, channel_id, guild_id, embeds, is_bot, is_human, is_webhook
"message_delete"message_id, old_message, channel_id, guild_id
"reaction_add", "reaction_remove"emoji_name, emoji_id, user_id, member, message_id, channel_id, guild_id, is_animated
python
evt = await wait_for("message", timeout=60, check=same_person)
if evt is not None:
    delete_message(evt.channel_id, evt.message_id)   # not evt.id

Example: wait for a reaction

python
msg = send_message(channel, "React with ✅ to confirm.")
add_reactions(msg, "✅")

def confirmed(evt):
    return evt.message_id == msg.id and evt.user_id == user.id and evt.emoji_name == "✅"

evt = await wait_for("reaction_add", timeout=60, check=confirmed)

dispatch#

Fires a clock event right now, in this server. Your Clock event, or a wait_for("clock"), picks it up.

python
dispatch(event)

event must be a ClockEvent(custom_id, metadata, server). Anything else fails with "This event can't be dispatched".

python
dispatch(ClockEvent("refresh_board", {"by": user.id}, server))

To fire a clock later instead, use schedule_clock. See Scheduling.

Event classes#

You can pass these instead of a name, or check for them in your function:

MessageCreateEvent, MessageDeleteEvent, ReactionEvent, ReactionAddEvent, ReactionRemoveEvent, ComponentInteraction, ModalInteraction.

PreviousTimeNext Utilities

On this page

  • wait_for
  • What you get back
  • dispatch
  • Event classes
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