# Apm Ticket System

{% hint style="info" %}
This guide is specifically for apms, and will be unsuitable for those who are not an apm.\
For those who are not an apm, visit [Ticket System](/botwiz-guides/botwiz-guides-1/slash-commands/ticket-system.md).
{% endhint %}

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. Everything will be explained, and you will be guided through - so don't worry!&#x20;

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 apms using a /mass command for example;
* Or, have each ticket created by apms using a 'mass' button.

{% tabs %}
{% tab title="Create a Ticket with a Command" %}
**In this tab, it will detail how to create the following embed and the '/mass' command.**

<figure><img src="/files/ZNGqBvIHiFYVSCL03O12" alt=""><figcaption></figcaption></figure>

Before creating your `/mass` command, you will need a way to send your ticket information, such as the embeds in the image above.

Start by creating a new command and place a Permissions Condition block to ensure not everybody can use the command. Afterwards, feel free to place action blocks to represent your ticket's information.

<figure><img src="/files/AVQ6o8drwZmI5RwTZD2W" alt=""><figcaption></figcaption></figure>

After, you'll need to create your `/mass` command, which will used to create a ticket. In this command, you will start with a 'Create Channel' block. Follow the rest of the guide for the next steps.
{% endtab %}

{% tab title="Create a Ticket with a Button" %}
**In this tab, it will detail how to create the following embed with buttons.**

<figure><img src="/files/KwcY9uhzDD5D9rTkD1x5" alt=""><figcaption></figcaption></figure>

To start, head to your bot's Dashboard, and select the 'Commands' tab. From here, create a new command. When creating your command, make sure to select 'ephemeral'; this means that each message reply will be hidden.

<figure><img src="/files/j6zLlK8w0ElLvKyrWnHb" alt=""><figcaption></figcaption></figure>

Once in your command builder, you'll notice a good few action blocks. A few may seem the same, however there are a few key differences. Below, are an example of action blocks with buttons:

<figure><img src="/files/pwhmgw3BsRkoMxrHcWZ8" alt=""><figcaption></figcaption></figure>

| Left Blocks                                                         | Right Blocks                                                                                          |
| ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| On the left, these are messages that **do not** reply to a message. | On the right, these messages reply, such as to the previous message, a select message or the command. |

Using the information above, start your ticket command by placing down some action blocks to represent your format.

#### Creating Buttons

Here, you can create buttons with different functions, such as:

* To send a message each time a button is clicked (use any message block);
* Give a role to the user who clicks the button (use an 'Add Roles' block); or
* To create a ticket system: allowing apms to mass with you.&#x20;

<figure><img src="/files/ZqsPcJj62rEDzrYztxLc" alt=""><figcaption></figcaption></figure>

#### Custom Emojis in Buttons

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:`.

<figure><img src="/files/h5oxYhaQK5sl86E23a3Z" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="/files/NvebC4rD642BSPhIdJ2z" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

#### 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.

Select a tab below to see an example of what your builder should look like thusfar.

{% tabs %}
{% tab title="Create a Ticket with a Command" %}

<figure><img src="/files/P3OIn6gM3DZ2qWp1bF2Q" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Create a Ticket with a Button" %}

<figure><img src="/files/ETeOpFcLSJgd0WuopRI6" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

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

<figure><img src="/files/kHXZ1sfuIkzCO79WBCje" alt=""><figcaption></figcaption></figure>

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="/files/FxWRiTOSABUN9DQ4Gok5" 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="/files/4Qfx7rw49tBEf2iGsBZt" 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="/files/xstTpVyGNWWDEqiJO2Kk" 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="/files/D6YSqRsHYhhFSuQKQltv" 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 & Channels](/botwiz-guides/discord-guides/categories-and-channels.md)!
{% 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="/files/1MUDfbvKhwTRjY9cH3tv" 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="/files/K1Wr2OXbqwBTDwwLyIRZ" 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="/files/iESZD5s4WAnFB7DSDw60" 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="/files/6rcTBFMuH5EHmHu9o5mi" 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="/files/hCHxOUSYb1po2tcq0yFE" 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="/files/FTTkPxVZFhiO4z06GzAj" 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="/files/h5oxYhaQK5sl86E23a3Z" 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.

![](/files/2tZynxkhkeBhguGG4t1k)

</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="/files/HB71HbIdSz5eqgVBqqyz" 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="/files/Anx4D6sERDY0gaKvy2dP" 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="/files/BP0hjX5SeQFlRCoYtNfR" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/c5JprqKsOUPtRFdWpEum" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/efpgSSqf5WNXTzvz0ou8" 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="/files/Qdlg1KzXkJytrPoBdLvH" 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 %} |        |

## Follow-up Replies

The following will be an example of typical replies sent in an apm portal. Feel free to follow these steps, or customize them to how you'd like!

### Sending the Ad

There are multiple ways to ask the ticket opener for their server's ad.&#x20;

1. You can ask the apm to send it as normal; or
2. You can ask the apm to send the ad through a modal.

In order to pin the server ad, or setup any [Broken mention](broken://pages/L1WIFIMGNjENi0lofECf), you must run the ad through a modal.

{% tabs %}
{% tab title="Ask as Normal" %}

<figure><img src="/files/G9awYsZfnONtzOjJJTkv" alt=""><figcaption></figcaption></figure>

Above is an example of how your builder should look currently, including future steps.

Here, your '1st Block' will be asking the user to send their ad. No checks will be made here, and their server ad will not be pinned. In this example, I have set up my 1st Block to ask the user to click 'Continue' once they have sent their ad in codeblock. For example:

<figure><img src="/files/oT7aX2iVNBh03JMb39u1" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Using a Modal" %}
First, we'll work on your first ticket message, such as the one below.

<figure><img src="/files/Kr9DmgjHZVKFVbiFvAgS" alt=""><figcaption></figcaption></figure>

Start by editing your action block to ask for the apm's server ad. Your action block must be either a button, select menu or its own separate command. Without this, you will not be able to use a modal.

{% hint style="info" %}
Modals will only work when connected to a trigger. Triggers include:

1. When a command is executed; or
2. When a button or select menu has been selected.
   {% endhint %}

<figure><img src="/files/bXuWnA7ysskTNzGz8gly" alt=""><figcaption></figcaption></figure>

If you are new to modals, visit this [documentation page](https://docs.botwiz.dev/docs/blocks/actions/message-or-embed/modal). However, I have set up my modal with the following settings:

1. Title: `Send your Server's Ad`
2. Custom ID: `ticket`

When creating my modal item (question), I have entered the following:

1. Component Identifier: `ad`
2. Component Label: `Paste your Server's Ad below in Codeblock`
3. Component Type: `Paragraph Text`
4. Component Required: `true`

All other options were left as default. With these settings, my modal looks like:

<figure><img src="/files/MDVr5evrQRF3lyhK1M4J" alt=""><figcaption></figcaption></figure>

To send the server ad entered, you can use a "Send a Message" block, with your modal's variable as the content. For instance, my modal's variable is `{modal_ticket_ad}`, as my Custom ID is 'ticket' and my Component Identifier is 'ad'.

<figure><img src="/files/iR0GCM9oi9q9ZhXXxQGo" alt=""><figcaption></figcaption></figure>

To pin the server ad, use a 'Pin a Message' block, and select your 'Send a Message' block.

<figure><img src="/files/siilcfEsOTAkZeutyKOB" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

### Giving Access

After the server ad has been sent, this is typically when apms will start posting. Here, you can either tag yourself, or a helper role, asking to verify the server before confirming they can mass.

To help, there are some [Broken mention](broken://pages/L1WIFIMGNjENi0lofECf) that can be manually performed by your bot to remove the need to manually approve each server ad.

{% tabs %}
{% tab title="Straight to Posting - no checks" %}
Here, we'll have the following:

<figure><img src="/files/MUDsnpsY1VKNDX9y3jqm" alt=""><figcaption></figcaption></figure>

Starting with your 'Add Roles' block, set your block to have the following settings:

<figure><img src="/files/SRiznJqPA7zSYdi6yi0o" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
'Message Author' is another way to refer to the interacting user. \
In this instance, it would be the user who clicks the 'Click 2 Continue' button.
{% endhint %}
{% endtab %}

{% tab title="Manual Checks" %}
Before giving access, you can send a message to your helpers / you, to ask for a manual check. Here, you can add a staff-only 'Approve' button, which'll lead into giving the ticket opener access to your servers and massing information.

For this, your builder will end up looking like the following:

<figure><img src="/files/ki5WYa7m2duKqmlk3b6i" alt=""><figcaption></figcaption></figure>

First, lets start by creating the message showing how to tag a role and a specific user. This will be your "Asks for a Manual Check".

Feel free to use the following [message format](https://discord.com/developers/docs/reference#message-formatting) guide on how to tag users or roles for example.

<figure><img src="/files/nwmrKQ5x8ybgbssLhRAD" alt=""><figcaption></figcaption></figure>

#### Approve Button

To have an approve button, you'll need to make sure the user interacting with that button has a specific role, or is a specific user. To do this, place a 'Role Condition' and/or a 'User Condition' block after your 'Approve' button. To use both conditions, you can do the following:

<figure><img src="/files/wHeKKdROU1zDaA5cnsBr" alt=""><figcaption></figcaption></figure>

#### How to get a Role or User ID

If you're unsure how to get a User or Role ID, you will need to have Developer Mode enabled in your Discord Settings. Head to yoru Settings > Advanced and enable Developer Mode. Then, right click any user or visit your Server Role Settings, and right click a role to get it's ID.

To add custom emojis to a button, see [#custom-emojis-in-buttons](#custom-emojis-in-buttons "mention").

#### Getting the Ticket Opener's ID

To add the access role to the ticket opener, you'll need a unique variable. As, if you use your approve button, `{interaction[member.id]}` will return your user ID instead of the ticket openers.

If you did not use the [#remove-permissions](#remove-permissions "mention") method, you will not have the unique variable you need already setup. To do this, head to the unique variable tab to create a new unique variable.

<figure><img src="/files/BP0hjX5SeQFlRCoYtNfR" alt=""><figcaption></figcaption></figure>

After, create a new unique value with the following settings:

<figure><img src="/files/n3c0k84hW7ZoSnOzIAxb" alt=""><figcaption></figcaption></figure>

This unique variable will store the ticket opener's ID. Though, to set this up you will need to place a 'Set Variable' block after your 'Create a Channel' block, as shown:

<figure><img src="/files/IJa9TsmYdksFayiWsjEx" alt=""><figcaption></figcaption></figure>

Now, in your 'Add Roles' block, you can use `{unique_ticket_opener}` as the user ID.

<figure><img src="/files/e2FylKRzP7BcEkoloV1W" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

Next, to create the "Posting Info" embed, I have used a 'Send Embed & Button' block. Cutomize this to how you would like, and make sure to send this message to your Ticket channel.&#x20;

### Sep or Batch Option

First, we'll need to ask if the apm would like their ad to be posted separately or in a batch. Next, if the user picks separately then we will need to see how long. Here, by using the buttons, you can add sep options - such as 30 minutes, 1 hour or overnight.

After each option, we will need a message block for your bot to notify you of which option they chose.

Feel free to use the following screenshot to see how to layout your action blocks.

<figure><img src="/files/6idlsrXX0WTjzuHm8A3b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Make sure that each of your messages go to your Ticket channel. You can do this by using:

![](/files/iXbcL28vjF9mnMuXdyAp)

Also, make sure to use your own `{created_channel_00000}` variable. \
You can find this at your 'Create a Channel' block.
{% endhint %}

#### How to Limit Some Options

If you'd like to make the 'overnight' option exclusive to a role, for example, you can add a 'Role Condition' block for example.&#x20;

With a role condition block, it will make sure that the user who interacts with the button has the role. If not, then any blocks in the 'Else' condition will be performed. If the user does infact have the role, any blocks in the comparison will be performed.

### End of the Mass

Here, you can add a way for ticket openers to be notified when their ticket has been posted. \
This step is similar to [#sep-or-batch-option](#sep-or-batch-option "mention").

Below is an example of how to ask the user, and to then let you know what the apm would prefer.

<figure><img src="/files/ef6hjY5cY46r17ntwXXz" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
To link multiple blocks together, you will need to use a merge block. \
See the screenshot above for an example.
{% endhint %}

## Miscellaneous Options

You can add more to your ticket system, including:

1. [Ticket Limits](/botwiz-guides/botwiz-guides-1/apm-guides/apm-ticket-system/ticket-limits.md): such as 1 ticket per user, or 1 ad in each ticket.

Click any of the above titles to be directed to a subpage containing the selected guide(s).

{% hint style="info" %}
More miscellaneous options coming soon...
{% endhint %}


---

# 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/apm-guides/apm-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.
