Discord Bot DSL - Documentation

Discord Bot DSL Documentation

Developed for Hayden Bradley (K25072606) for 7CCSMMDD Model-driven Engineering

GitHub Repository: https://github.com/6ccs3mde-7ccsmmdd-classroom-2024-25/coursework-EggsLeggs

Introduction

This documentation covers the Discord Bot DSL, a language for defining Discord bots declaratively.

There are 3 top-level block: bot, event and action. These let you define the core settings for your bot, the events it should listen for and the actions it should perform.

Use the sidebar to browse blocks and event/action types. Each page links to the relevant fields, arguments and properties for that block.

Top-level blocks

The top-level blocks are the core building blocks of the Discord Bot DSL.

  • bot - core bot settings (token, intents)
  • event - event handlers
  • action - reusable actions

Properties and dot-path notation

Most fields support dot-path notation to access properties of context variables.

For example, the `user_id` field in the `send_dm` action can be set to the user ID of the member who triggered the event by using the `member.user.id` path expression.

The available properties depend on the event type and/or arguments. You can find the available properties for an event type in the sidebar.

Example

bot {
    token = "your_token_here"
    intents = ["Guilds", "GuildMessages", "MessageContent", "GuildMembers"]
}

action "send_dm" "welcomeDm" {
    user_id = member.user.id
    content = "Welcome to the server!"
}

action "add_role" "memberRole" {
    role_id = "0123456789012345678"
    user_id = member.user.id
}
event "guildMemberAdd" "welcomeFlow" {
    actions = [action.send_dm.welcomeDm, action.add_role.memberRole]
}

This example shows a bot with a token and intents, and a welcome flow event that sends a welcome message and adds a role to the user when they join the server.

Defines the core settings for your Discord bot, including its token and the gateway intents it subscribes to.

Fields

FieldTypeRequiredDescription
token string optional Your bot's secret token from the Discord Developer Portal. Keep this private - anyone with your token can control your bot. If this isn't provided, the generator will make a .env.example file.
intents string[] required The gateway intents your bot needs. Only declare the intents you actually use - some require explicit approval for verified bots.

Possible Intents:

Guilds GuildMembers GuildModeration GuildExpressions GuildIntegrations GuildWebhooks GuildInvites GuildVoiceStates GuildPresences GuildMessages GuildMessageReactions GuildMessageTyping DirectMessages DirectMessageReactions DirectMessageTyping MessageContent GuildScheduledEvents AutoModerationConfiguration AutoModerationExecution GuildMessagePolls DirectMessagePolls

Example

bot {
  token "your-token-here"
  intents ["GuildMessages", "MessageContent"]
}

Runs when something happens in your Discord server, or defines a slash command when the event type is "command".

Event Types

Event blocks have a type, which determines the type of event it is. The type may provide additional fields and/or properties for actions.

Fields

Shared Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Command-only Fields

These fields are only available for command events. See the command event type for more information.

FieldTypeRequiredDescription
description string optional A short explanation shown in Discord's command picker when a user types /. Must be 1-100 characters.
arguments string optional The inputs a user provides when running the command. For example, a /greet command might have a user argument for /greet @Alice.

Example

action "send_message" "pingReply" {
  channel_id = interaction.channelId
  content = "Pong!"
}

event "command" "ping" {
  description = "Ping the bot"
  action = action.send_message.pingReply
}

event "ready"

Discord Docs ↗

Fired once when the bot connects to Discord and is ready to receive events.

Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Example

action "send_message" "logReady" {
  channel_id = "000000000000000000"
  content = "Bot is online!"
}

event "ready" "onReady" {
  action = action.send_message.logReady
}

Context Variables

No context variables.

event "guildMemberAdd"

Discord Docs ↗

Fired when a new member joins the guild. Requires the GuildMembers privileged intent.

Required intents: GuildMembers

Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Example

action "send_message" "welcome" {
  channel_id = "000000000000000000"
  content = "Welcome to the server!"
}

event "guildMemberAdd" "onJoin" {
  action = action.send_message.welcome
}

Context Variables

member GuildMember

The member who joined.

PathTypeDescription
member.user.id Snowflake The member's user ID.
member.user.username string The member's username.
member.user.displayName string The user's global display name (ignores server nickname).
member.guild.id Snowflake The guild this member belongs to.
member.roles RoleManager The member's role collection.
member.displayName string The member's server display name (nickname, falling back to global display name).

event "guildMemberRemove"

Discord Docs ↗

Fired when a member leaves or is removed from the guild. Requires the GuildMembers privileged intent.

Required intents: GuildMembers

Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Example

action "send_message" "goodbye" {
  channel_id = "000000000000000000"
  content = "A member has left the server."
}

event "guildMemberRemove" "onLeave" {
  action = action.send_message.goodbye
}

Context Variables

member GuildMember

The member who left.

PathTypeDescription
member.user.id Snowflake The member's user ID.
member.user.username string The member's username.
member.user.displayName string The user's global display name (ignores server nickname).
member.guild.id Snowflake The guild this member belongs to.
member.roles RoleManager The member's role collection.
member.displayName string The member's server display name (nickname, falling back to global display name).

event "guildMemberUpdate"

Discord Docs ↗

Fired when a member's roles, nickname, or other properties change. Exposes before and after context variables to compare the member state. Requires the GuildMembers privileged intent.

Required intents: GuildMembers

Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Example

action "send_message" "notifyUpdate" {
  channel_id = "000000000000000000"
  content = "A member's profile was updated."
}

event "guildMemberUpdate" "onUpdate" {
  action = action.send_message.notifyUpdate
}

Context Variables

before GuildMember

The member state before the change.

PathTypeDescription
before.user.id Snowflake The member's user ID.
before.user.username string The member's username.
before.user.displayName string The user's global display name (ignores server nickname).
before.guild.id Snowflake The guild this member belongs to.
before.roles RoleManager The member's role collection.
before.displayName string The member's server display name (nickname, falling back to global display name).

after GuildMember

The member state after the change.

PathTypeDescription
after.user.id Snowflake The member's user ID.
after.user.username string The member's username.
after.user.displayName string The user's global display name (ignores server nickname).
after.guild.id Snowflake The guild this member belongs to.
after.roles RoleManager The member's role collection.
after.displayName string The member's server display name (nickname, falling back to global display name).

event "messageCreate"

Discord Docs ↗

Fired when a message is sent in any channel the bot can see. Requires the GuildMessages and MessageContent intents.

Required intents: GuildMessages MessageContent

Fields

FieldTypeRequiredDescription
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

Example

action "send_message" "echo" {
  channel_id = message.channel.id
  content = "You said something!"
}

event "messageCreate" "onMessage" {
  action = action.send_message.echo
}

Context Variables

message Message

The message that was sent.

PathTypeDescription
message.author.id Snowflake The message author's user ID.
message.channel.id Snowflake The channel the message was sent in.
message.guild.id Snowflake The guild the message was sent in.
message.content string The text content of the message.

event "command"

Discord Docs ↗

A slash command registered with Discord. Supports description, arguments, and action references.

Fields

FieldTypeRequiredDescription
description string optional A short explanation shown in Discord's command picker when a user types /. Must be 1-100 characters.
arguments string optional The inputs a user provides when running the command. For example, a /greet command might have a user argument for /greet @Alice.
action string optional A single action reference or inline action block this event executes when triggered. Use actions (plural) for multiple. You can only use one of action or actions.
actions string[] optional An array of action references this event executes when triggered. References use the form action.<type>.<name>. You can only use one of action or actions.

arg

Defines a single argument for a slash command, including its name, type, description, and whether it is required.

FieldTypeRequiredDescription
type string required The argument type: String, Integer, Boolean, User, Channel, Role, or Number.
description string required A short explanation of this argument shown to users in Discord's command picker.
required string optional Whether this argument must be provided. Defaults to false. Required arguments must appear before optional ones.
Argument Types
TypeDescription
String String - A text value. Shown to users as a text input field.
Integer Integer - A whole number, e.g. 5 or 100. Shown as a number input.
Boolean Boolean - A true/false value. Shown as a toggle.
User User - A Discord user, selected from a mention or user picker.
Channel Channel - A Discord channel, selected from a channel picker.
Role Role - A Discord role, selected from a role picker.
Number Number - A decimal number, e.g. 3.14.

Example

action "send_message" "greet" {
  channel_id = interaction.channelId
  content = "Hello!"
}

event "command" "greet" {
  description = "Greet a user"
  arguments {
    arg "user" {
      type = User
      description = "The user to greet"
      required = true
    }
  }
  action = action.send_message.greet
}

Context Variables

interaction ChatInputCommandInteraction

The command interaction from the user.

PathTypeDescription
interaction.user.id Snowflake The invoking user's ID.
interaction.channelId Snowflake The channel where the command was used.
interaction.guild.id Snowflake The guild where the command was used.
interaction.member GuildMember The guild member who invoked the command.

action

Defines a reusable action that can be referenced by event handlers. Actions have a specific type and a set of fields for that type.

Action Types

Action blocks have a type, which determines the type of action it is. The type may provide additional fields and/or properties for actions.

action send_message

Discord Docs ↗

Sends a message to a text channel.

Fields

FieldTypeRequiredDescription
channel_id snowflake optional The channel to send the message in. Defaults to the channel where the event occurred.
Defaults: messageCreatemessage.channel.id commandinteraction.channelId
content template required The message text. Supports ${arg} interpolation in command contexts.

Example

action "send_message" "pingReply" {
  channel_id = interaction.channelId
  content = "Pong!"
}

event "command" "ping" {
  description = "Ping the bot"
  action = action.send_message.pingReply
}

action send_dm

Discord Docs ↗

Sends a direct message to a user.

Fields

FieldTypeRequiredDescription
user_id snowflake optional The user to DM. Defaults to the user who triggered the event.
Defaults: guildMemberAddmember.user.id guildMemberRemovemember.user.id guildMemberUpdateafter.user.id messageCreatemessage.author.id commandinteraction.user.id
content template required The DM text. Supports ${arg} interpolation in command contexts.

Example

action "send_dm" "welcome" {
  user_id = member.user.id
  content = "Welcome to the server!"
}

event "guildMemberAdd" "onJoin" {
  action = action.send_dm.welcome
}

action add_role

Discord Docs ↗

Adds a role to a guild member.

Fields

FieldTypeRequiredDescription
role_id snowflake required The ID of the role to add.
user_id snowflake optional The member to receive the role. Defaults to the user who triggered the event.
Defaults: guildMemberAddmember.user.id guildMemberUpdateafter.user.id commandinteraction.user.id
guild_id snowflake optional The guild in which to add the role. Defaults to the guild where the event occurred.
Defaults: guildMemberAddmember.guild.id guildMemberUpdateafter.guild.id messageCreatemessage.guild.id commandinteraction.guild.id

Example

action "add_role" "giveMember" {
  role_id = "000000000000000001"
  user_id = member.user.id
  guild_id = member.guild.id
}

event "guildMemberAdd" "onJoin" {
  action = action.add_role.giveMember
}

action remove_role

Discord Docs ↗

Removes a role from a guild member.

Fields

FieldTypeRequiredDescription
role_id snowflake required The ID of the role to remove.
user_id snowflake optional The member to remove the role from. Defaults to the user who triggered the event.
Defaults: guildMemberAddmember.user.id guildMemberUpdateafter.user.id commandinteraction.user.id
guild_id snowflake optional The guild context. Defaults to the guild where the event occurred.
Defaults: guildMemberAddmember.guild.id guildMemberUpdateafter.guild.id messageCreatemessage.guild.id commandinteraction.guild.id

Example

action "remove_role" "stripMember" {
  role_id = "000000000000000001"
  user_id = interaction.user.id
  guild_id = interaction.guild.id
}

event "command" "kick" {
  description = "Remove the member role from a user"
  action = action.remove_role.stripMember
}