Docs
Dashboard
KyroScript

Messages, members and roles

These functions talk to Discord. Each run can make a limited number of Discord actions (see limits).

Messages

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}")
Command file
command: serverinfo
description: Show info about this server
---
card = embed(
    title=server.name,
    description="Welcome to our server!",
    color="#7289DA",
    fields=[
        {"name": "Members", "value": text(server.member_count), "inline": true},
        {"name": "Boosts", "value": text(server.boosts), "inline": true},
        {"name": "Created", "value": format_time(server.created_at, "date"), "inline": true},
    ],
)
reply(card)

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")
✨ Tip Giving roles and moderating follow Discord’s rules: your bot’s role has to be above the role it gives, and the person running the command needs the same power. A script can’t let someone do more than they already could. To make a whole command staff-only, use the permissions: setting.

Server and channels

Scripts can make, change and delete channels and roles, lock channels, start threads and change server settings, with allow: server. As with roles, the person running the command needs the matching permission (like Manage Channels), and new roles never get permissions: give those in Discord.

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"
Command file
command: ticket
description: Open a private support ticket
permissions: manage_channels
allow: server, channels
---
room = create_channel("ticket-{user.name}", private=true, allow=[user, "Moderator"])
send(room, "Hi {user.mention}! Tell us what you need and a moderator will be with you soon.")
reply("Your ticket is open: {room.mention}", private=true)
Was this page helpful?