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

Moderation commands

Make /kick, /ban, /timeout and /purge for your moderators, with a permission check and a log message.

You will make four commands for your moderators:

CommandWhat it does
/kickRemoves a member from the server. They can join again.
/banRemoves a member and stops them from joining again.
/timeoutStops a member from talking for a while.
/purgeDeletes many recent messages at once.

Each one checks that the member who runs it is allowed to, and posts a note in a log channel.

Before you start#

Make a text channel named mod-log. The commands post there.

Check that the bot's role is above the roles of the members it acts on. Move it up under Server Settings → Roles. Discord never lets a bot act on the server owner.

Two layers of protection#

Use both:

  1. Hide the command. In the command form, switch to Advanced. Open Permissions and pick a permission under Discord permissions, for example Kick Members. Discord then hides the command from members without it.
  2. Check in code. require_permission("kick_members") stops the command if the member lacks the permission. Server admins can change the hiding in Discord's own settings, so the code check is the one you can trust.

If the member does not have the permission, require_permission stops the command and shows an error. You can write your own text with error_message="...".

/kick#

Create a slash command named kick with two arguments:

TypeNameRequired
MembertargetYes
TextreasonNo

Pre-hook:

python
require_permission("kick_members")

if target.id == user.id:
    set_error("You can't kick yourself.")

why = reason or "No reason given"
kick_member(target, reason=why)
send_message("mod-log", f"👢 {user.mention} kicked {target.mention}. Reason: {why}")
set_content(f"Kicked {target.display_name}.")

set_error stops the command and shows the text to the member. Nothing after it runs.

/ban#

Same arguments as /kick.

Pre-hook:

python
require_permission("ban_members")

if target.id == user.id:
    set_error("You can't ban yourself.")

why = reason or "No reason given"
ban_member(target, reason=why)
send_message("mod-log", f"🔨 {user.mention} banned {target.mention}. Reason: {why}")
set_content(f"Banned {target.display_name}.")

/timeout#

TypeNameRequiredDescription
MembertargetYesWho to time out
TextlengthYesFor example 10 minutes, 1 hour, 2 days

Pre-hook:

python
require_permission("moderate_members")

timeout_member(target, length)
send_message("mod-log", f"🔇 {user.mention} timed out {target.mention} for {length}.")
set_content(f"Timed out {target.display_name} for {length}.")

A timeout can be up to 28 days. A longer time, or a time the bot cannot read, stops the command with an error.

To lift a timeout early, make /untimeout with remove_timeout(target).

/purge#

TypeNameRequiredDescription
IntegeramountYesHow many messages to delete

Pre-hook:

python
require_permission("manage_messages")

if amount < 1 or amount > 100:
    set_error("Pick a number from 1 to 100.")

purge_messages(channel.id, amount)
send_message("mod-log", f"🧹 {user.mention} deleted {amount} messages in {channel.mention}.")
set_content(f"Deleted {amount} messages.")

Under Behavior, turn on Only the user sees the reply. Otherwise the reply lands in the channel you just cleaned.

Watch out

Discord only bulk-deletes messages newer than 14 days. Older messages are skipped. The bot needs Manage Messages and Read Message History in that channel.

Permissions the bot needs#

CommandThe bot needs
/kickKick Members
/banBan Members
/timeoutTimeout Members
/purgeManage Messages, Read Message History

If the bot lacks one, the member sees an error like "Missing permission to kick member".

Limits#

Each command sends one log message. A free server can send 3 extra messages per run, so you have room to spare. See Limits.

Learn more#

  • Checks lists require_permission, allowed_roles, cooldown and the other gates.
  • Members and roles lists kick_member, ban_member, timeout_member and more.
  • Auto moderation handles spam and scam links without a moderator.
PreviousSocial alertsNext Levels and XP

On this page

  • Before you start
  • Two layers of protection
  • /kick
  • /ban
  • /timeout
  • /purge
  • Permissions the bot needs
  • Limits
  • 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