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

Event variables

The ready-made variables your code gets in each kind of command and event.

Your code starts with some variables already filled in, like user and server. Which ones you get depends on what started the code.

The tables below list them. Using a variable that is not in the list fails with a "not defined" error. All helper functions in the API reference are there too, unless a section says otherwise.

To read what is on each object, see Objects.

Slash command#

VariableWhat it is
userThe member who ran the command.
channelThe channel it ran in.
serverThe server.
interactionThe slash command interaction.
command_nameThe command name.
unix_timestampThe current time as a Unix number.
variablesYour saved server variables.
Each optionEvery option, under its own name. An option amount is the variable amount.

Only in the post-hook, after the reply is sent:

VariableWhat it is
responseThe reply message.
response_dmThe DM reply, when the reply went to DMs.
response_feedbackThe short "Command executed" note, when the reply went to DMs or another channel.
viewYour View, after it finished.
pre_hook_failedTrue when the pre-hook stopped with an error.
pre_hook_cooldownTrue when a cooldown stopped the command.
pre_hook_errorThe pre-hook's error, if any.

Options win

An option named user replaces the user variable. Name options so they do not clash, like target instead of user.

See How commands run for the order of pre-hook, reply and post-hook.

Text command#

The same as a slash command, with two changes:

  • message is the message that ran the command. There is no interaction.
  • Saved variables load first, so a built-in name wins over a variable with the same name.

See Text commands.

Member Join, Leave and Update#

VariableWhat it is
userThe member.
serverThe server.
eventThe raw Discord event.
unix_timestampThe current time.
old_userThe member before the change. Leave and Update only.
added_roleThe role ID, or list of IDs, that was added. Update only.
removed_roleThe role ID, or list of IDs, that was removed. Update only.

There is no channel and no message. message_id and channel_id are None.

Message#

Runs for every new message. Premium only.

VariableWhat it is
userThe author.
messageThe message.
channelWhere it was sent.
message_id, channel_idTheir IDs.
server, event, unix_timestampAs above.

Skip bots first

This event also runs for bot messages, your own bot's too. Start with a check, or your bot can answer itself forever:

python
if user is None or user.is_bot:
    return

Reaction#

Runs when someone adds or removes one of the emojis you list on the event.

VariableWhat it is
userWho reacted.
channelThe channel.
emoji_nameThe emoji, or the custom emoji's name.
emoji_idThe custom emoji's ID. None for normal emojis.
action"add" or "remove".
message_id, channel_idThe message and its channel.
server, event, unix_timestampAs above.

There is no message object. Get it with get_message(channel_id, message_id).

Voice Join, Leave and Change#

VariableWhat it is
userThe member.
channelThe channel they joined. On Leave, the channel they left.
old_channelThe channel before. None on a fresh join.
server, event, unix_timestampAs above.

Note

Voice Join also runs when someone moves between channels. Check old_channel is None to know it was a fresh join.

Thread#

Runs when a thread is made, changed or deleted.

VariableWhat it is
channel, threadThe thread.
action"create", "update" or "delete".
userThe thread owner. None on delete.
parent_idThe channel the thread is in.
thread_idThe thread ID.
eventThe raw Discord event.

There is no server here. Use event.get_guild().

Clock#

Runs when a clock or a repeating job fires. See Scheduling.

VariableWhat it is
custom_idThe clock or job name.
metadataThe data you gave when you set it.
server, event, unix_timestampAs above.

In the event's custom IDs, list exact names, or end with * to match many, like remind_*.

Vote (top.gg)#

Runs when someone votes for your server on top.gg.

VariableWhat it is
userThe voter. None when they left the server.
user_idThe voter's ID. Always set.
weekendTrue for a double-value weekend vote.
vote_countThe server's total votes, this one included.
server, event, unix_timestampAs above.

Button Click / Select Menu Change#

Runs when someone clicks a saved button or picks from a saved menu. List the component IDs on the event.

VariableWhat it is
interactionThe click. interaction.values holds menu picks.
userWho clicked.
custom_idWhich button or menu.
messageThe message the button is on.
channelThe channel.
message_id, channel_idTheir IDs.
server, unix_timestampAs above.

Also here: defer_response, respond_interaction, send_modal, cooldown, require_permission, allowed_roles, banned_roles, allowed_channels, banned_channels.

Answer within 3 seconds

Call defer_response() first, then respond_interaction(...). Or open a form with await send_modal(form) as the first answer. See Interactions.

Modal Submit#

Runs when someone sends a form. The event's custom IDs list the form IDs.

VariableWhat it is
interactionThe submit.
userWho sent it.
custom_idThe form ID.
valuesA dict of each field's ID to what they typed.
channel, channel_idThe channel.
server, unix_timestampAs above.
python
answer = values.get("reason", "")

There is no message. The same 3-second rule and helpers as button clicks apply. See Forms.

Autocomplete#

Runs while someone types into a command option that has autocomplete. You return the suggestions.

VariableWhat it is
interactionThe autocomplete request.
optionThe option being typed. option.value is the text so far.
server, channel_id, unix_timestampAs above.

There is no user. Reply in under 3 seconds with respond_options. Write await yourself.

python
await respond_options(options, auto_filter=True)
ArgumentWhat it does
optionsA list of text, or of AutocompleteChoice(name=..., value=...). Only 25 show.
auto_filterTrue keeps only choices that contain what was typed.
python
await respond_options([
    AutocompleteChoice(name="Red team", value="red"),
    AutocompleteChoice(name="Blue team", value="blue"),
])

name is what people see. value is what your command gets. Do not fetch or sleep here: it is too slow.

PreviousObjectsNext /8ball

On this page

  • Slash command
  • Text command
  • Member Join, Leave and Update
  • Message
  • Reaction
  • Voice Join, Leave and Change
  • Thread
  • Clock
  • Vote (top.gg)
  • Button Click / Select Menu Change
  • Modal Submit
  • Autocomplete
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