Docs
Dashboard
KyroScript

Function reference

Every built-in function. name? means optional. Optional values can be given by name, like reply("hi", private=true).

Messages and embeds

reply(message: any, embed?: embed, private?: bool) → none

Reply to whoever ran the command (or to the message that triggered the automation).

  • message: text, a number or an embed
  • private: only the person who ran it sees it (slash commands)
reply("Hello, {user.name}!")
send(channel: channel|text, message: any, embed?: embed) → noneNeeds allow: channels

Post in a channel (by channel, id or name).

send(get_channel("logs"), "{user.name} used /hello")
dm(message: any, embed?: embed) → bool

Send a direct message to the person who triggered the script. Returns false if their DMs are closed.

dm("Thanks for joining!")
react(emoji: text) → none

React to the triggering message (or the bot’s reply).

react("🎉")
unreact(emoji: text) → none

Remove the bot’s reaction.

embed(title?: text, description?: text, color?: text|number, url?: text, image?: text, thumbnail?: text, footer?: text, author?: text, fields?: list) → embed

Make an embed to pass to reply, send or dm.

  • color: "#7289DA" or a name like "blue"
  • fields: a list of maps: {"name": …, "value": …, "inline": true}
reply(embed(title=server.name, description="Welcome!", color="#7289DA"))
purge(count: number, user?: member|user) → numberNeeds allow: moderation

Delete recent messages in this channel (Discord only allows messages under 14 days old). Returns how many were deleted. Needs Manage Messages. Not in automations.

  • count: 1–100
  • user: only their messages
n = purge(20)
delete_message() → noneNeeds allow: moderation

Delete the message that started the script (a prefix command, or the message or reaction an automation runs on). Great for filters.

delete_message()
pin_message(pinned?: bool) → noneNeeds allow: moderation

Pin (or unpin) the message that started the script. Needs Manage Messages.

  • pinned: false unpins
pin_message()
create_thread(name: text, on_message?: bool) → channelNeeds allow: channels

Start a thread in this channel and give it back, so you can send() to it.

  • on_message: start it on the message that started the script
thread = create_thread("Discussion: {args.topic}")

Members and roles

give_role(member: member|user, role: role|text) → noneNeeds allow: roles

Give someone a role. The bot’s role must be above it, and so must the role of whoever ran the command.

  • role: a role, its id or its name
give_role(member, "Verified")
take_role(member: member|user, role: role|text) → noneNeeds allow: roles

Take a role away.

has_role(member: member|user, role: role|text) → bool

Whether someone has a role.

if has_role(member, "VIP"):
has_permission(member: member|user, permission: text) → bool

Whether someone has a server permission (administrators have them all).

  • permission: like "manage_messages", "ban_members", "administrator"
if has_permission(member, "manage_messages"):
get_member(user: user|text) → member

Look up someone in this server. Returns none if they aren’t here.

  • user: a user or their id
kick(member: member|user, reason?: text) → noneNeeds allow: moderation

Kick someone. The person running the command needs Kick Members.

timeout(member: member|user, minutes: number, reason?: text) → noneNeeds allow: moderation

Time someone out (up to 28 days). The person running the command needs Moderate Members.

ban(user: member|user|text, reason?: text, delete_days?: number) → noneNeeds allow: moderation

Ban someone (they don’t have to be in the server). The person running the command needs Ban Members. Not in automations.

  • user: a person or their id
  • delete_days: delete their messages from the last 0–7 days
ban(args.who, "Spam")
unban(user: user|text, reason?: text) → boolNeeds allow: moderation

Lift a ban. Returns false if they weren’t banned. Needs Ban Members. Not in automations.

  • user: a person or their id
unban(args.id)
set_nickname(member: member|user, nickname?: text) → noneNeeds allow: server

Change someone’s nickname in this server (none resets it). Needs Manage Nicknames, unless it’s your own and you can change your nickname.

  • nickname: none resets it
set_nickname(user, "🎉 {user.name}")
create_role(name: text, color?: text, hoist?: bool, mentionable?: bool) → roleNeeds allow: server

Make a role (with no permissions: give those in Discord). Needs Manage Roles.

  • color: like #ff8800
  • hoist: show members separately
r = create_role("Event winner", color="#f1c40f")
edit_role(role: role|text, name?: text, color?: text, hoist?: bool, mentionable?: bool) → noneNeeds allow: server

Change a role’s name, colour, or whether it’s shown separately or mentionable. Needs Manage Roles, and the role has to be below yours and the bot’s.

edit_role("VIP", color="#9b59b6")
delete_role(role: role|text, reason?: text) → noneNeeds allow: server

Delete a role for good. Needs Manage Roles. Not in automations.

delete_role("Old event")

Server and channels

create_channel(name: text, type?: text, category?: channel|text, topic?: text, private?: bool, allow?: list) → channelNeeds allow: server

Make a channel. Needs Manage Channels.

  • type: text (default), voice or category
  • category: the category to put it in
  • private: hide it from @everyone
  • allow: members and roles who can see a private channel
room = create_channel("ticket-{user.name}", private=true, allow=[user])
edit_channel(channel: channel|text, name?: text, topic?: text, slowmode?: number, nsfw?: bool, category?: channel|text) → noneNeeds allow: server

Change a channel’s name, topic, slowmode, age limit or category. Needs Manage Channels.

  • slowmode: seconds between messages (0 turns it off)
edit_channel(channel, slowmode=10)
lock_channel(channel?: channel|text, locked?: bool) → noneNeeds allow: server

Stop @everyone sending messages in a channel (or let them again). Needs Manage Channels.

  • channel: this channel if left out
  • locked: false unlocks
lock_channel(locked=true)
delete_channel(channel: channel|text, reason?: text) → noneNeeds allow: server

Delete a channel for good. Needs Manage Channels. Not in automations.

delete_channel(channel)
edit_server(name?: text, verification?: text, system_channel?: channel|text) → noneNeeds allow: server

Change the server’s name, verification level or system channel. Needs Manage Server. Not in automations.

  • verification: none, low, medium, high or highest
  • system_channel: where Discord posts join messages
edit_server(verification="high")
list_channels(type?: text) → list

The server’s channels (up to 100), in order.

  • type: text, voice or category
for c in list_channels("text"): print(c.name)
list_roles() → list

The server’s roles (up to 100), highest first.

top = list_roles()[0]
get_channel(channel: text) → channel

Find a channel in this server. Returns none if there isn’t one.

  • channel: id or name
get_role(role: text) → role

Find a role in this server. Returns none if there isn’t one.

  • role: id or name
config.get(key: text) → any

Read one of the bot’s settings.

  • key: "currency", "currency_name", "prefix", "bot_name"

Economy

economy.balance(user: user|member) → number

Coins in someone’s wallet.

coins = economy.balance(user)
economy.bank(user: user|member) → number

Coins in someone’s bank.

economy.give(user: user|member, amount: number, reason?: text) → numberNeeds allow: balances

Add coins to someone’s wallet. Returns their new balance.

economy.give(user, 100, "daily reward")
economy.take(user: user|member, amount: number, reason?: text) → numberNeeds allow: balances

Take coins from someone’s wallet. Fails if they don’t have enough. Returns their new balance.

economy.top(limit?: number) → list

The richest members here (up to 25): a list of maps with "user" and "coins".

Levels

levels.xp(user: user|member) → number

Someone’s XP in this server.

levels.level(user: user|member) → number

Someone’s level in this server.

level = levels.level(user)
levels.rank(user: user|member) → number

Someone’s position on the leaderboard (1 = top).

levels.add_xp(user: user|member, amount: number) → numberNeeds allow: xp

Give (or take) XP. Level-up messages and role rewards still happen. Returns their new XP.

  • amount: negative to take XP away

Storage

storage.get(key: text, default?: any, user?: user|member, shared?: bool) → any

Read a saved value (or the default if there isn’t one).

  • user: keep a separate value per person
  • shared: the same value in every server
visits = storage.get("visits", 0)
storage.set(key: text, value: any, user?: user|member, shared?: bool) → noneNeeds allow: storage

Save a value: text, a number, true/false, a list or a map.

storage.set("visits", visits + 1)
storage.add(key: text, amount?: number, user?: user|member, shared?: bool) → numberNeeds allow: storage

Add to a saved number (1 by default) and return the new total. Safe when two people run it at once.

count = storage.add("uses")
storage.delete(key: text, user?: user|member, shared?: bool) → noneNeeds allow: storage

Delete a saved value.

Text

text(value: any) → text

Turn anything into text.

upper(text: text) → text

UPPERCASE.

lower(text: text) → text

lowercase.

trim(text: text) → text

Remove spaces from both ends.

split(text: text, separator?: text) → list

Split text into a list.

  • separator: default: any spaces
words = split("a b c")
join(list: list, separator?: text) → text

Join a list into text.

join(names, ", ")
replace(text: text, find: text, with: text) → text

Replace every match.

starts_with(text: text, start: text) → bool

Whether text starts with something.

ends_with(text: text, end: text) → bool

Whether text ends with something.

find(text: text, part: text) → number

Where something first appears in text (0 = the start), or -1.

Math

number(value: text|number|bool) → number

Turn text into a number. Returns none if it isn’t one.

amount = number(args.amount)
round(number: number, decimals?: number) → number

Round to the nearest whole number (or to some decimals).

floor(number: number) → number

Round down.

ceil(number: number) → number

Round up.

abs(number: number) → number

Remove the minus sign.

min(numbers: number|list, …) → number

The smallest of some numbers (or of a list).

min(5, 3, 9)
max(numbers: number|list, …) → number

The largest of some numbers (or of a list).

sum(list: list) → number

Add up a list of numbers.

random(low: number, high: number) → number

A random whole number from low to high (both included).

roll = random(1, 6)

Lists and maps

len(value: text|list|map) → number

How long text is, or how many items a list or map has.

contains(in: text|list|map, value: any) → bool

Whether text contains some text, a list contains a value, or a map has a key. Same as “value in thing”.

append(list: list, value: any) → none

Add a value to the end of a list.

remove(list: list, value: any) → bool

Remove the first matching value. Returns whether one was found.

pop(list: list) → any

Remove and return the last item (none if empty).

sort(list: list, reverse?: bool) → list

A sorted copy of a list of numbers or of text.

reverse(list: list) → list

A reversed copy of a list.

shuffle(list: list) → list

A shuffled copy of a list.

choice(list: list) → any

A random item from a list.

choice(["rock", "paper", "scissors"])
range(start: number, end?: number, step?: number) → list

Numbers counting up: range(5) is [0, 1, 2, 3, 4], range(1, 4) is [1, 2, 3].

slice(value: text|list, start: number, end?: number) → any

Part of some text or a list, from start up to (not including) end. Negative numbers count from the end.

keys(map: map) → list

A map’s keys, as a list.

values(map: map) → list

A map’s values, as a list.

get(map: map, key: text, default?: any) → any

A map’s value for a key, or the default if it isn’t there.

Types

type_of(value: any) → text

What kind of value something is: "number", "text", "list", "user"…

Time

now() → number

The current time, in seconds since 1970 (a Unix timestamp).

format_time(time: number, style?: text) → text

A time that shows in each reader’s own time zone.

  • time: seconds since 1970
  • style: "relative" (in 2 hours), "date", "time" or "full"
reply("Ends {format_time(now() + 3600)}")
wait(seconds: number) → none

Pause for a moment (up to 10 seconds in total per run).

wait(2)

Errors and debugging

fail(message: text) → none

Stop right here and show the message as an error. Can’t be caught by try/except.

fail("You need at least 100 coins.")
error(message: text) → none

Raise an error that a try/except around it can catch.

print(values: any, …) → none

Write a line to the test runner and the run log (not to Discord).

Internet

integrations.weather(place: text) → mapNeeds allow: internet

The weather right now somewhere: place, country, temp_c, temp_f, feels_like_c, humidity, wind_kph, condition and emoji. none if the place isn’t found.

  • place: a city or place name
w = integrations.weather("London")
integrations.define(word: text) → mapNeeds allow: internet

An English dictionary entry: word, phonetic and meanings (a list of maps with part, definition and example). none if it isn’t found.

d = integrations.define("serendipity")
integrations.wikipedia(topic: text) → mapNeeds allow: internet

A short Wikipedia summary: title, summary, url and image. none if there’s no article.

w = integrations.wikipedia("Octopus")
integrations.crypto_price(coin: text, currency?: text) → mapNeeds allow: internet

A coin’s price: coin, currency, price and change_24h (percent). none if the coin isn’t found.

  • coin: e.g. bitcoin, ethereum, solana
  • currency: usd (default), eur, gbp…
p = integrations.crypto_price("bitcoin")
integrations.steam_game(name: text) → mapNeeds allow: internet

A game on Steam: name, price (text), free, url, image and metacritic. none if it isn’t found.

g = integrations.steam_game("Hades")
secret(name: text) → secretNeeds allow: internet

An API key you saved in the dashboard. It can only be put in http request headers or query values, and only for the site it’s tied to: scripts can never read it. Max only.

key = secret("WEATHER_KEY")
http.get(url: text, headers?: map, query?: map) → mapNeeds allow: internet

Fetch a page from a site in your allowlist. Gives a map with status, ok, json (if the answer was JSON) and text. Max only.

  • url: https, on a site in your allowlist
r = http.get("https://api.example.com/stats", query={"id": "123"})
http.post(url: text, json?: any, headers?: map, query?: map) → mapNeeds allow: internet

Send JSON to a site in your allowlist. Gives a map with status, ok, json and text, like http.get. Max only.

  • url: https, on a site in your allowlist
  • json: sent as JSON (up to 16 KB)
r = http.post("https://api.example.com/scores", json={"user": user.id, "score": 10})
Was this page helpful?