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

Web and files

Call web APIs, download files, render image templates, ask AI, run saved scripts and find emojis.

These functions reach outside the command: the web, your image templates, AI and your saved scripts.

Write await in front of fetch, render_template, ask_ai and load_script. The bot adds it for load_file.

Limits#

Each run has its own count. Pre-hook and post-hook share it.

WhatFreePremium
fetch different requests per run520
load_file different links per run520
Download size, each5 MB100 MB
Download time, each20 seconds120 seconds
render_template per minute, whole server20120
Images inside one template515
ask_ainot availableavailable

Asking for the same fetch or load_file link again in the same run is free. The bot reuses the first answer.

Note

The bot only fetches public web addresses. Links to private or local network addresses are refused.

fetch#

Calls a web address and returns the answer.

python
await fetch(url, method="GET", to="json", dynamic=False, **options)
ArgumentWhat it does
urlThe web address.
methodGET, POST, PUT, PATCH or DELETE.
toHow to read the answer: json (a dict or list), text or bytes.
dynamicTrue asks again every time, even for the same link. Use it for random answers.
**optionsSent with the request, for example headers=, json= or data=.

Returns None when the site answers with an error (status 400 or higher), or when the answer cannot be read as to.

Example: a random cat fact

python
data = await fetch("https://catfact.ninja/fact")
if data is None:
    set_error("The cat fact site is down. Try again later.")
set_content(data["fact"])

Example: send JSON to an API

python
await fetch(
    "https://example.com/api/report",
    method="POST",
    json={"user": str(user.id), "reason": reason},
    headers={"Authorization": "Bearer " + server_var("api_key")},
)

Random answers

Two calls to the same link in one run return the same answer. For a new random result each time, pass dynamic=True.

load_file#

Downloads a file from a link so you can attach it to a message.

python
load_file(file, filename=None)
ArgumentWhat it does
fileThe link to the file.
filenameThe name Discord shows. Optional.

Returns None when the download fails. Fails with "File size is greater than 5MB" when the file is too big for your plan.

python
pic = load_file("https://example.com/banner.png", "banner.png")
send_message(channel, "New banner!", attachments=[pic])

render_template#

Draws an image from one of your Image Templates and returns it as a file.

python
await render_template(name, **values)
ArgumentWhat it does
nameThe template name from the dashboard.
**valuesA value for each variable in the template. avatar also fills the template's avatar picture.
python
card = await render_template(
    "rank-card",
    name=user.display_name,
    avatar=user.avatar_url,
    level=member_var("level", 1),
)
add_attachment(card)

Put the result in attachments=, add_attachment(...), or a Message(image=...).

Fails when a variable has no value, and names the missing ones. On a free server, going over 20 renders a minute fails. On premium the call waits for a free slot.

ask_ai#

Premium only. Asks an AI model a question and returns the answer as text.

python
await ask_ai(
    prompt,
    instructions=None,
    max_words=None,
    use_context=True,
    cache=False,
)
ArgumentWhat it does
promptThe question.
instructionsHow the AI should answer, like a role or a tone.
max_wordsA shorter limit for the answer. The most is 1,024 words.
use_contextTrue tells the AI about your server and its commands.
cacheTrue reuses a recent answer to the same question.
python
answer = await ask_ai(question, instructions="Answer in one friendly sentence.")
set_content(answer)

The longest prompt depends on the plan: Starter 500, Basic 1,000, Advanced 2,000 characters. On a free server it fails with "ask_ai is a premium feature".

load_script#

Runs one of your saved Scripts inside this command.

python
await load_script(script_id, **variables)
ArgumentWhat it does
script_idThe script's ID from the dashboard.
**variablesExtra variables the script can read.

The script sees all of your command's variables, plus the ones you pass. When it changes a plain variable, your command does not see the change.

python
await load_script("give-xp", amount=10)

A script cannot load another script. A disabled script fails and says why.

emoji#

Finds an emoji and returns it ready to put in a message.

python
emoji(query, as_emoji=False)
ArgumentWhat it does
queryA custom emoji's name or ID from this server, or a name like ":fire:".
as_emojiTrue returns the emoji object instead of text.
python
set_content(f"GG {emoji('pepe_happy')} {emoji(':tada:')}")

Returns nothing when no emoji matches.

PreviousPaginatorsNext Scheduling

On this page

  • Limits
  • fetch
  • load_file
  • render_template
  • ask_ai
  • load_script
  • emoji
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