# Events

> The server events an event flow can react to, and the tokens each one provides.

Source: https://docs.buildcord.dev/reference/events/

An [event flow](https://docs.buildcord.dev/nodes/triggers/event) runs when one of these happens. Events need a gateway bot. Each is delivered to the bot under a *gateway intent*, which the builder adds to the blueprint for you.

Every event also gives `{event}`: everything Discord sent with it. Reach into it with dots, such as `{event.joined_at}`, or hand it to [Run code](https://docs.buildcord.dev/nodes/integrations/run-code) as `ctx.event`. The tokens below are the parts most flows want, by name.

| Event | Fires when | Intent |
| --- | --- | --- |
| Member joins | Someone joins the server. | GuildMembers |
| Member leaves | Someone leaves or is removed. | GuildMembers |
| Member changes | Someone's roles, nickname or timeout change. | GuildMembers |
| Server boosted | A member starts boosting. | GuildMembers |
| Member banned, Member unbanned | Someone is banned, or a ban is lifted. | GuildModeration |
| Message sent | Any message in a channel the bot can read. | GuildMessages |
| Message edited | Someone edits a message. | GuildMessages |
| Message deleted | A message is deleted. | GuildMessages |
| Reaction added, Reaction removed | Someone reacts to a message, or takes a reaction away. | GuildMessageReactions |
| Joins voice | A member connects to a voice channel. | GuildVoiceStates |
| Moves voice channel | A member moves from one voice channel to another. | GuildVoiceStates |
| Leaves voice | A member disconnects from voice. | GuildVoiceStates |
| Thread created | A new thread or forum post. | Guilds |
| Channel created, Channel deleted | A channel or category is added or removed. | Guilds |
| Role created, Role deleted | A role is added or removed. | Guilds |
| Invite created | Someone makes an invite link. | GuildInvites |

> **Warning: Privileged intents**
>
> Discord restricts some intents, such as reading message content and listening to members. Buildcord switches them on for your bot when you deploy, and lists them under **Settings → Permissions**. Once a bot is in 100 or more servers, Discord asks you to apply for them in the developer portal.

## What came before

Discord says what something is now, not what it was. For **Member changes**, **Message edited**, **Message deleted**, **Moves voice channel** and **Leaves voice**, the bot remembers what it has seen since it connected (the last few thousand messages, the members and who is in voice) to say what changed. Right after a restart or a deploy, a message sent before then has no `{message.before}`, and a member's first change has no `{member.rolesAdded}`.

Every event also has `{user.id}`, `{user.name}` and `{user.mention}` for who did it, when Discord says, and `{server.id}`. Steps that act on "the member" act on them.

## Member joins

| Token | Value |
| --- | --- |
| `{member.joinedAt}` | When they joined |
| `{member.accountAge}` | How old their Discord account is, in seconds |
| `{user.createdAt}` | When their account was made, in seconds since 1970 |

## Member leaves

| Token | Value |
| --- | --- |
| `{member.roles}` | The roles they had, when the bot had seen them |

## Member changes

| Token | Value |
| --- | --- |
| `{member.roles}` | Their roles now, as IDs separated by commas |
| `{member.rolesAdded}`, `{member.rolesRemoved}` | The roles just given and taken away |
| `{member.nickname}`, `{member.nicknameBefore}` | Their nickname now and before |
| `{member.timedOut}` | `true` if they're timed out now |

It doesn't fire for changes nobody can see, such as a new avatar.

## Server boosted

| Token | Value |
| --- | --- |
| `{server.boosts}` | How many boosts the server now has |
| `{server.boostTier}` | The server's boost level |

## Member banned, Member unbanned

`{user.mention}` and the rest are who was banned or unbanned.

## Message sent

| Token | Value |
| --- | --- |
| `{message.content}` | The text of the message |
| `{message.link}` | A link straight to the message |
| `{message.id}` | The message's ID |
| `{message.attachments}` | How many files are attached |
| `{message.files}` | The address of each file attached, one per line |
| `{message.author}`, `{message.author.id}` | Who sent it |
| `{message.mentions}` | Everyone the message mentions |
| `{message.roleMentions}` | The roles it mentions |
| `{message.replyTo}`, `{message.replyTo.id}` | The text and ID of the message it replies to |
| `{member.roles}` | The sender's roles |

## Message edited

The same as **Message sent** for the message as it is now, and `{message.before}`: what it said before.

## Message deleted

| Token | Value |
| --- | --- |
| `{message.id}` | The message's ID |
| `{message.content}` | What it said, when the bot saw it sent |
| `{user.mention}` | Who wrote it, when the bot saw it sent |

## Reaction added

| Token | Value |
| --- | --- |
| `{reaction.emoji}` | The emoji that was added |
| `{message.id}`, `{message.link}` | The message reacted to |
| `{message.content}`, `{message.author}` | What it said and who wrote it, when the bot saw it sent |

## Reaction removed

| Token | Value |
| --- | --- |
| `{reaction.emoji}` | The emoji that was taken away |
| `{message.id}`, `{message.link}` | The message |
| `{user.mention}` | Who took it away |

## Joins voice

| Token | Value |
| --- | --- |
| `{voice.channel}` | The voice channel they joined |
| `{voice.memberCount}` | How many people are now in the channel |

## Moves voice channel

| Token | Value |
| --- | --- |
| `{voice.channel}` | The channel they moved to |
| `{voice.previousChannel}` | The one they came from |
| `{voice.memberCount}` | How many are now in the new channel |

## Leaves voice

| Token | Value |
| --- | --- |
| `{voice.channel}` | The channel they left |
| `{voice.memberCount}` | How many are left in it |

## Thread created

| Token | Value |
| --- | --- |
| `{thread.name}` | The thread's title |
| `{thread.id}`, `{thread.parent}` | The thread, and the channel or forum it was made in |
| `{thread.link}` | A link straight to the thread |

## Channel created, Channel deleted

| Token | Value |
| --- | --- |
| `{channel.name}`, `{channel.id}`, `{channel.mention}` | The channel |
| `{channel.type}` | `text`, `voice`, `category`, `announcement`, `forum` or `stage` |
| `{channel.parent}` | The category it's in |

## Role created, Role deleted

| Token | Value |
| --- | --- |
| `{role.id}` | The role's ID |
| `{role.name}`, `{role.mention}` | For a new role: its name and a mention |

## Invite created

| Token | Value |
| --- | --- |
| `{invite.url}`, `{invite.code}` | The invite |
| `{invite.channel}` | The channel it lands in |
| `{invite.maxUses}` | How many times it can be used, 0 for no limit |
| `{invite.expiresIn}` | How many seconds it lasts, 0 for ever |
| `{user.mention}` | Who made it |
