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

Checks

Cooldowns, permission checks, role and channel rules, and custom error messages.

A check stops the command when a rule is not met. The person sees an error message, and nothing else runs.

Put checks at the top of the pre-hook, before any work.

These functions work in slash commands, text commands and component handlers. You do not need to write await in front of them.

Tip

You do not need if around a check. Each one stops the command by itself, with a good message.

cooldown#

Makes a member wait before using the command again.

python
cooldown(time, key=None, error_message=None, count=1)
ArgumentWhat it does
timeHow long to wait, in words: "30 seconds", "1 hour", "1 day".
keyWho shares the cooldown. Default is the member who ran it.
error_messageYour own message. It can use the placeholders below.
countHow many uses are allowed before the wait starts.
python
cooldown("1 day", error_message="You already claimed today. Come back %relative%.")
coins = int(member_var("coins", 0)) + 100
update_member_var("coins", coins)
set_content(f"You got 100 coins! You now have {coins}.")

Placeholders for error_message:

PlaceholderBecomesShows in Discord as
%time%5 minutesplain text
%relative%a Discord time tagin 5 minutes, counting down by itself
%at%a Discord time tag9:46 PM, in each reader's time zone
%timestamp%1788731206the raw number of seconds

Use %time% for "try again after %time%". Use %relative% for "try again %relative%".

Who shares the cooldown

keyEffect
not setEach member has their own cooldown.
server.idOne cooldown for the whole server.
channel.idOne cooldown per channel.
[user.id, channel.id]One per member, per channel.

In a component handler

In a component handler, cooldown(time, key=None) does not stop the script. It returns False when the click may go on, or the time left as text when it must wait.

python
left = cooldown("10 seconds")
if left:
    set_error(f"Slow down. Try again in {left}.")

require_permission#

Lets the command run only for members with all these Discord permissions. Administrators always pass.

python
require_permission(*permissions, error_message=None)
python
require_permission("ban_members")

Write permission names in lowercase with _. Common ones:

administrator, manage_server, manage_roles, manage_channels, manage_messages, kick_members, ban_members, timeout_members, mention_roles, send_messages, view_channel.

A wrong name stops the script and lists every valid name.

allowed_roles#

Lets the command run only for members with at least one of these roles.

python
allowed_roles(*roles, error_message=None)
python
allowed_roles("Staff", "Moderator", error_message="Only staff can use this.")

Roles can be role objects, role IDs or exact role names.

banned_roles#

Stops members with any of these roles from running the command.

python
banned_roles(*roles, error_message=None)
python
banned_roles("Muted")

allowed_channels#

Lets the command run only in these channels.

python
allowed_channels(*channels, error_message=None)
python
allowed_channels("bot-commands", error_message="Use this in #bot-commands.")

banned_channels#

Stops the command in these channels.

python
banned_channels(*channels, error_message=None)

set_error#

Stops the script at once and shows your message as an error.

python
set_error(message)
python
amount = int(amount)
if amount <= 0:
    set_error("The amount must be more than 0.")

set_error works everywhere, including events. In a command, the message is the reply.

Tip

You can also set some rules on the dashboard, with no code. Open a command and pick Allowed roles and Allowed channels.

PreviousStorageNext Views

On this page

  • cooldown
  • require_permission
  • allowed_roles
  • banned_roles
  • allowed_channels
  • banned_channels
  • set_error
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