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

Interactions

Answer clicks, menu picks and form submits in time, then send or change the reply.

An interaction is something a member does that Discord expects an answer to: running a slash command, clicking a button, picking from a menu, or submitting a form.

Discord gives the bot 3 seconds to answer. With no answer, the member sees "This interaction failed".

Answering in time#

Only three things count as an answer:

CallUse when
defer_response(action="update")You will change the message the button is on.
defer_response(ephemeral=True)You will send a new message later. ephemeral=True makes it visible to the clicker only.
await send_modal(form)You open a form. Opening it is the answer.

Answer first, before reading a database or editing messages. Those can use up the 3 seconds.

Slash commands answer for you

With Show "thinking…" on, a slash command answers Discord at once. Your pre-hook then has as long as it needs. Turn it off only to open a form or to answer yourself.

respond_interaction is not an answer. It changes an answer that already exists. Call defer_response first.

defer_response#

Answers the current interaction now, and shows "thinking…" until you send the real reply. Works in component handlers, modal handlers and slash commands.

python
defer_response(ephemeral=False, action="create", modal=None)
ArgumentWhat it does
ephemeralTrue: the reply that follows is visible to the clicker only.
action"create": the reply is a new message. "update": the reply changes the message with the button.
modalA form to open instead. Same as send_modal(form).

Any action other than "create" is treated as "update".

python
# Button Click event
defer_response(ephemeral=True)
coins = int(member_var("coins", 0))
respond_interaction(interaction, f"You have {coins} coins.")

defer#

Does the same as defer_response, but for an interaction you pass in. Use it in View callbacks, where the click is the callback's interaction. Needs await.

python
await defer(interaction, ephemeral=False, action="create", modal=None)
python
@button(label="Next", custom_id="next")
async def next_page(self, interaction, component):
    await defer(interaction, action="update")
    self.page += 1
    await self.update_view()

respond_interaction#

Sends or changes the reply to an interaction you already answered.

python
respond_interaction(
    interaction,
    content=...,
    embed=...,
    message=None,
    attachments=...,
    components=...,
    empty=False,
)
ArgumentWhat it does
interactionThe interaction. In a handler, use the interaction variable.
contentThe text.
embedOne embed.
messageA Message(...) with text and an embed.
attachmentsA list of files. None removes existing files.
componentsA ComponentBuilder or a View.
emptyTrue changes nothing.

Leave out an argument to keep what is there. Pass None to remove it.

python
# Button Click event: change the panel after a click
defer_response(action="update")
respond_interaction(interaction, content="Ticket closed.", components=None)

send_modal#

Opens a form as the answer. Needs await. See Modals.

python
await send_modal(form)
await send_modal(form, interaction)   # inside a View callback

A handler that opens a form must not call defer_response first. That would be a second answer, and Discord refuses it.

interaction#

The interaction variable holds the current interaction. Useful parts:

PartWhat it is
interaction.user, interaction.memberWho did it.
interaction.channel_id, interaction.guild_idWhere.
interaction.custom_idThe button, menu or form name. Clicks and submits only.
interaction.valuesWhat was picked in a menu, as a list. Menus only.
interaction.command_name, interaction.optionsSlash commands only.
interaction.localeThe member's Discord language.

See Objects for the full list.

PreviousModalsNext Paginators

On this page

  • Answering in time
  • defer_response
  • defer
  • respond_interaction
  • send_modal
  • interaction
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