# Ticket System

The following guide and subguides will use APIs, regex, and both commands and events.&#x20;

Although this is fairly complicated, it will introduce you up to new features, and explain them in depth; allowing you to explore new ways to create.

If you have any questions throughout or get stuck, feel free to visit our [Support Server](https://discord.gg/5qRpsctzjB).

## Introduction

If you are new to BotWiz, and have not yet added your bot: [click here](https://docs.botwiz.dev/docs/getting-started/adding-token-to-botwiz) to learn how!

Below are two options to creating your ticket system. You can either:

* Have each ticket made by using a command; or
* Have each ticket created by using a button.

If you wish for your tickets to be created via a button, start your command with a buttons action block.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2Ffe1PdW09IPHCNWcucdI6%2Fimage.png?alt=media&#x26;token=774b8ec6-09ba-4c05-9efe-090b6d96e2ea" alt=""><figcaption></figcaption></figure>

#### Interaction Variable Examples

| User Variables                      | Explaination                                                                                                 |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `{interaction[member]}`             | Tag the interacting user.                                                                                    |
| `{interaction[member.id]}`          | Get the interacting user's ID.                                                                               |
| `{interaction[member.username]}`    | Grab the interacting user's username.                                                                        |
| `{interaction[member.displayName]}` | Display the interacting user's name.                                                                         |
| `{interaction[channel.id]}`         | Shows the current channel's ID.                                                                              |
| `{interaction[message.id]}`         | <p>Grabs the interacted message ID.<br><strong>This only works after a trigger (e.g. a button).</strong></p> |

Find more combinations for the interaction variable by [clicking here](https://discord.js.org/docs/packages/discord.js/14.14.1/User:Class#defaultAvatarURL).

## Creating the Tickets

To create a ticket, start by placing a Create Channel action block.

For this guide, I have set my ticket names to `ticket-{interaction[member.displayName]}`. This means that with each new ticket made, it will be named `ticket-catnip` for example.

Additionally, you can edit the type of channel; meaning you can have your tickets held in a text channel or a thread. When selecting a thread option, all threads will be made in the current channel.

#### Optional Create Channel Options

Below are additional options, allowing you to fully customize your newly created channel.

{% tabs %}
{% tab title="Topic" %}
In each text channel, you can set a topic. Topics can be used to describe the channel's purpose, or state any quick rules such as "No Spamming!".

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FBf0Gx15UmsxAeFBxzblT%2Fimage.png?alt=media&#x26;token=abcb90e1-4d9f-4d81-8920-376644fac03e" alt=""><figcaption></figcaption></figure>

When a topic is set, everyone who can see the channel will see the topic at the top.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FFNB1gDDFoUhrhj5w9Z9Z%2Fimage.png?alt=media&#x26;token=b3c3e445-42b1-4d5d-9e29-a34351a4bdce" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="NSFW" %}
Will this channel hold content that should only be visible to adults? If so, tick this option!

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2F2JaDTXFZ5F3ltSSePKy6%2Fimage.png?alt=media&#x26;token=e31a6390-06b5-4340-a628-bb8d33636d06" alt=""><figcaption></figcaption></figure>

When a channel is marked as NSFW, it will warn users before entering the channel.

Some users may have Family Centre enabled or safe settings, meaning NSFW messages, or channels, are blurred or blocked. Find out more [here](https://discord.com/safety/360043653552-age-restricted-content-on-discord).

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2F01D1wV3Ov9THgjPaNHjv%2Fimage.png?alt=media&#x26;token=91af412f-ceaa-484c-8ae4-8c206784ff8f" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Position" %}
This is where you channel will be placed in your server's channel list.

Low positions, starting at 1, will place your channel at the top of the list. Higher positions will place your channel at the bottom of the channel list.

Find out more at [categories-and-channels](https://docs.botwiz.dev/botwiz-guides/discord-guides/categories-and-channels "mention")!
{% endtab %}

{% tab title="Slowmode" %}
Slowmode can be setup, whereby members will rate limited with each message.&#x20;

A slowmode can be set between 0-21600 seconds.&#x20;

Users with the the `manage_messages` or `manage_channel` permission and bots are unaffected; meaning they can send any message without being rate limited.
{% endtab %}

{% tab title="Reason" %}
This reason will be used for your server's audit logs.&#x20;

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FbnKJHZ8kMDG1jotx5fj7%2Fimage.png?alt=media&#x26;token=cc89d867-df2c-4b33-b9ec-ee4230d0eb78" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Adding Permissions

When your ticket channel is created, it will be subject to the permissions that its parent channel has.

<details>

<summary>What is a Parent Channel?</summary>

A parent channel is the 'host' channel. For example, a channel's parent is its category.

A newly created channel will adopt the same permissions as it's parent channel.

For channels without a category, they will have the parent channel of the server. Meaning, it's parent channel ID will be the server's ID. The channel will not have any permissions, until they are manually set.

For threads, their parent channel will be the the channel the thread is hosted in. Similarly, forum posts will have the forum channel as its parent.

</details>

To override these permissions, and have your own, you'll need to use an API block. This is needed to make sure that your ticket opener has permissions to view their ticket.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FUIEBWv978chvzunc12sq%2Fimage.png?alt=media&#x26;token=f1869e0c-412e-4d36-8b7a-46c54dadc66f" alt=""><figcaption></figcaption></figure>

### **Permissions API**

Method: <mark style="color:orange;">`PUT`</mark> \
URL: `https://discord.com/api/v10/channels/{create_channel_00000[id]}/permissions/{interaction[member.id]}`

This API will edit your channel's permissions. In the URL, make sure to add your unique code. Do this by replacing `00000` with your own `create_channel`'s variable. You can access your code by visiting your Create Channel block.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FpERHLUfqkCNCPaB1YlS0%2Fimage.png?alt=media&#x26;token=09a06f98-95f0-4176-9185-7ba1715c696b" alt=""><figcaption></figcaption></figure>

To add a specific user, or role, replace `{interaction[member.id]}` with the user or role's ID.

{% hint style="info" %}
With `{interaction[member.id]}` in the URL, the interacting user (e.g. the user who clicks the 'Mass' button in this example), will be the one whose permissions you edit.
{% endhint %}

#### **HTTP Headers**

| Key           | Value             |
| ------------- | ----------------- |
| Authorization | `Bot {bot_token}` |

#### **Request Body**

Before entering your values below, you will need to use a permissions conversion tool.

Discord uses numbers, instead of the typical permissions such as `administrator` or `manage messages`. In order to get the permissions you'd like, you will need to use [this tool](https://botwiz.dev/free-tools/discord-permissions-calculator).

When using BotWiz's Permissions Calculator tool, first start by selecting the permissions you'd like to allow for the user or role you selected (in the ID part of the API's URL). Once finished, at the top of the page you will see **Conversion**. Copy the number and put this as your `allow` value.

For example, the conversion for the `view_channel` and `send_messages` permissions is `3072`.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FPHRaUyB8XRkYePGtGfOr%2Fimage.png?alt=media&#x26;token=63253e26-4f98-46b2-8d0c-3ef1bacdfa7c" alt=""><figcaption><p>BotWiz's Permissions Calculator Tool</p></figcaption></figure>

If you would like to also deny some permissions for your selected user or role, repeat the above steps but set the conversion number as the `deny` value.

| Key     | Value                        | Description                                                                                                                |
| ------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `type`  | `0` or `1` (see description) | <p>Put <code>1</code> if the ID in the URL belongs to a user.<br>Else, put <code>0</code> if the ID belongs to a role.</p> |
| `allow` | See above for instructions.  | The permissions to allow.                                                                                                  |
| `deny`  | See above for instructions.  | The permissions to deny.                                                                                                   |

To add more permissions, duplicate the API block and repeat the above blocks!

{% hint style="info" %}
An update is planned to introduce an "Edit Channel Permissions" block.
{% endhint %}

{% hint style="warning" %}
If the category your tickets are made in allows permissions for everyone for instance, and you would like to keep permissions private, then feel free to repeat the permissions API.
{% endhint %}

## Ticket Messages & Close Ticket

### How to Send Messages to a Ticket

To send any messages to your new channel, set your action block's location to the following:

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FK3e8izDx5IySR8iuhqAQ%2Fimage.png?alt=media&#x26;token=03133105-56c2-46b3-a0ef-c89a18550b5c" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can find your `{create_channel_00000}` variable in your 'Create Channel' block.

Using the above variable in the example image will not work for your command; each variable has a different code.

Blocks that reply to a message will **not** work.
{% endhint %}

### Creating the 'Close Ticket' Button

To create your button, you will need to use any 'Message Button' action block, with a button set up to act as the closing button. To send this message to the ticket channel, use your 'Create Channel' block's variable; this variable should look like `{create_channel_00000}`.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FB7MGGLQemBvHviAGt5ww%2Fimage.png?alt=media&#x26;token=5763a579-e30c-4cec-a1e5-6f3390eee516" alt=""><figcaption></figcaption></figure>

<details>

<summary>How to add Custom Emojis to Buttons</summary>

Type your emoji in a Discord channel. Before spending your custom emoji, put `\` before the emoji. This will change your text to the emoji's raw version, such as `:botwiz:`.

<img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FymcN0SBnau2nwhoo7UWr%2Fimage.png?alt=media&#x26;token=d1281723-7fcb-488d-89b4-73ed3319e62e" alt="" data-size="original">

Next, send the message and you will see that the message has sent the emoji's raw form, such as `<:botwiz:1249410551575089193>`. Copy the emoji's ID (the number), and paste this into the Button Emoji textbox, as shown below.

![](https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FqLxg1KN1nEEsGtMpI4p0%2Fimage.png?alt=media\&token=192a161f-a32b-4657-8d8d-47c65df1852f)

</details>

Depending on your settings, and your preferances, you can set up your 'close' button to:

1. Delete the ticket channel;
2. Remove the ticket opener's permissions to see the channel; or
3. **If your channel is a forum post or thread:** close and lock the post.

{% tabs %}
{% tab title="Delete the Ticket Channel" %}
For this, you'll simply need to place a 'Delete Channel' action block after your 'Close' button.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FT93AT2f1KBh6hc7MfYZQ%2Fimage.png?alt=media&#x26;token=717b8530-d4ac-42cf-91a5-8d8b1fba9b4a" alt=""><figcaption></figcaption></figure>

When selecting which channel to delete, remember to use your `{create_channel_00000}` variable from before. You can find this by selecting your 'Create Channel' block!

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FPslvuicu6w9Ejer6Noro%2Fimage.png?alt=media&#x26;token=a475458f-8351-4951-951d-9ac50bacca8c" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Remove Permissions" %}
This method will be useful to allow staff to assess a ticket, or to keep the ticket 'archived'.

First, we'll need to add a new Unique Variable. This will be used to retieve the ticket opener's ID. Since with each interaction, the interaction variables change, we need to store the ID of the user who clicked to open a ticket, not the user who clicked your 'Close Ticket' button.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FfiDCKrEsd6IpjibKwNZx%2Fimage.png?alt=media&#x26;token=0c30bda3-cd9b-4093-9a06-02e467cf08dc" alt=""><figcaption></figcaption></figure>

When creating your new Unique Variable, enter the following settings:

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FQaD1Q5RfO8r9SGHrorp7%2Fimage.png?alt=media&#x26;token=a47ffed2-3093-4dac-b1da-5d1d0adb1874" alt=""><figcaption></figcaption></figure>

To store the ticket opener's ID, place a 'Set Variable' block after your 'Create Channel' block.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2FnwWoBpJ4w12kabvjLgrF%2Fimage.png?alt=media&#x26;token=2d999aec-99bf-4354-9b1e-baf81dc097c3" alt=""><figcaption></figcaption></figure>

Now, we can place an API block after your 'Close Ticket' button. This will be used to remove the ticket opener's permissions to see the ticket. Any other members, such as staff members, will continue to see the ticket.

Name: `remove`\
Method: <mark style="color:red;">`DELETE`</mark> \
URL: `https://discord.com/api/v10/channels/{interaction[channel.id]}/permissions/{unique_ticket_opener}`

**HTTP Headers**

| Key             | Value             |
| --------------- | ----------------- |
| `Authorization` | `Bot {bot_token}` |
| {% endtab %}    |                   |

{% tab title="Close & Lock a Post" %}
Start by placing an API block after your 'Close Ticket' button. This will archive and lock the post.

<figure><img src="https://3071155663-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3kWzjw3glf7IkiBD8sfd%2Fuploads%2F693JcATj5FjXJFfX05dz%2Fimage.png?alt=media&#x26;token=2e9cdcbf-abff-4ad6-9194-2cc8bc1d20f8" alt=""><figcaption></figcaption></figure>

Name: `close`\
Method: <mark style="color:orange;">`PATCH`</mark> \
URL: `https://discord.com/api/v10/channels/{interaction[channel.id]}`

**HTTP Headers**

| Key             | Value             |
| --------------- | ----------------- |
| `Authorization` | `Bot {bot_token}` |

**Request Body**

| Key           | Value  |
| ------------- | ------ |
| `archived`    | `true` |
| `locked`      | `true` |
| {% endtab %}  |        |
| {% endtabs %} |        |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.botwiz.dev/botwiz-guides/botwiz-guides-1/slash-commands/ticket-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
