In this section, we will focus on describing for you how to create custom options in the dashboard and how they work.
How do I create my own option
Discord-Dashboard allows you to create a two-tier system of options because you can divide them into categories. Therefore, all you need to do in the config Dashboard is to place a category object in the Array and Option objects for that option category in the Array.
What does Category Object looks like
{ categoryId: 'unique_id', categoryName: "Category Name", categoryDescription: "Category Description", categoryOptionsList: [ categoryOptionObject, categoryOptionObject, ... ] }
Option | Type | |
---|---|---|
categoryId | String | Category ID (must be lowercase and unique). |
categoryName | String | Category name. Can include HTML code. |
categoryDescription | String | Category description. Can include HTML code. |
categoryOptionsList | Array | An Array of the categoryOptionObject Objects. |
What does Category Option Object looks like
{ /* Required options */ optionId: 'unique_id', optionName: "Option Name", optionDescription: "Option Description", optionType: <DBDFormType>, getActualSet: async ({guild,user}) => { return <DBDFormTypeValueType>; }, setNew: async ({guild,user,newData}) => { return <DBDFormTypeValueType>; }, /* Optional options */ allowedCheck: async ({guild,user}) => { if(guild.id == "123456789876")return {allowed: false, errorMessage: 'You cannot use this option - guild is blacklisted for it.'}; if(user.id == "123456789876")return {allowed: false, errorMessage: 'You cannot use this option - user is blacklisted for.'}; return {allowed: true, errorMessage: null}; } }
Option | Type | |
---|---|---|
optionId | String | Option ID (must be lowercase and unique). |
optionName | String | Option name. Can include HTML code. |
optionDescription | String | Option description. Can include HTML code. |
optionType | Object (DBD Form Type) | DBD Option Type. FormTypes are listed in this section of the tutorial. |
getActualSet | async Function | The function for which you should return the currently set value for the option. The function passes you a user and a guild Object. |
setNew | async Function | A function that the Dashboard performs whenever a user changes the settings of an option. It passes you the user , guild , and newData Objects. |
allowedCheck (optional) | async Function | A function that checks if the option should be enabled to be changed by the user on the guild. It passes you the user and guild Objects. |
What are getActualSet and setNew functions
Both of these functions serve the most important purpose of the dashboard – passing current data and saving new data to the database.
For example, if a user enters a page, you need to display the currently set prefix to them, right? That’s what the getActualSet function is for.
Conversely, if the user saves a new prefix, you need to set it. That’s what the setNew function does.
What are the FormTypes
If you want to create the ability to change the prefix for the user, you would use a text input with a character limit of 4, right? With Discord-Dashboard this is trivially easy because you just need to choose the right input type and give it settings like minimum and maximum character length, which is also trivially easy. And that’s what FormTypes are.
What FormTypes are available
There are quite a few FormTypes available, however, we are still updating their database to be richer. It will get even bigger for the upcoming Soft-UI Theme!
Let’s introduce you to all the available ones!
Please head to the next tutorial part.