Skip to content

Built-in config.js file

This file will handle your command permissions level setup and who is the bot owner, your bot admin, and bot support users. Build your own config.js file and define how your permissions level should work.

Tip

You can access the config variables by using "client.config"

Here is the default config.js that is used if no config file is found:

config.js
const { ChannelType } = require("discord.js");

const config = {
  ownerID: process.env.OWNER_ID,
  admins: process.env.OWNER_ID,
  support: process.env.OWNER_ID,
  prefix: "!",
  token: process.env.DISCORD_TOKEN,
  clientId: process.env.CLIENT_ID,
  guildId: process.env.DEVELOPMENT_GUILD_ID,
  toDeleteSlashCommand: "",
  displayAdminCommandCallsByNonAdmin: false,
  roles: {
    modRole: {
      name: "mod"
    },
    adminRole: {
      name: "admin"
    },
  },\
  permissions: [
    {
      level: 0,
      name: "User",
      check: () => true,
    },
    {
      level: 3,
      name: "Moderator",
      check: ({ guild, guildMember }) => {
        const modRole = guild.roles.cache.find(
          (r) => r.name.toLowerCase() === config.roles.modRole.name.toLowerCase()
        );
        if (modRole && guildMember.roles.cache.has(modRole.id)) {
          return true;
        } else {
          return false;
        }
      },
    },
    {
      level: 4,
      name: "Administrator",
      check: ({ guild, guildMember }) => {
        const adminRole = guild.roles.cache.find(
          (r) => r.name.toLowerCase() === config.roles.adminRole.name.toLowerCase()
        );

        if (adminRole && guildMember.roles.cache.has(adminRole.id)) {
          return true;
        } else {
          return false;
        }
      },
    },
    {
      level: 5,
      name: "Server Owner",
      check: ({ author, channel, guild }) => {
        return channel.type === ChannelType.GuildText
          ? guild.ownerId === author.id
            ? true
            : false
          : false;
      },
    },
    {
      level: 8,
      name: "Bot Support",
      check: ({ author }) => {
        if (!config.support) {
          if (config.ownerID === author.id) {
            return true;
          } else {
            return false;
          }
        }

        return config.support.includes(author.id);
      },
    },
    {
      level: 9,
      name: "Bot Admin",
      check: ({ author }) => {
        if (!config.admins) {
          if (config.ownerID === author.id) {
            return true;
          } else {
            return false;
          }
        }

        return config.admins.includes(author.id);
      },
    },
    {
      level: 10,
      name: "Bot Owner",
      check: ({ author }) => {
        return config.ownerID === author.id;
      },
    },
  ],
};

module.exports = config;
config.ts
import { CheckPermissions, Config } from "discord-features-handler";
import { ChannelType } from "discord.js";

const config: Config = {
  ownerID: process.env.OWNER_ID,
  admins: process.env.OWNER_ID,
  support: process.env.OWNER_ID,
  prefix: "!",
  token: process.env.DISCORD_TOKEN,
  clientId: process.env.CLIENT_ID,
  guildId: process.env.DEVELOPMENT_GUILD_ID,
  toDeleteSlashCommand: "",
  displayAdminCommandCallsByNonAdmin: false,
  roles: {
    modRole: {
      name: "mod"
    },
    adminRole: {
      name: "admin"
    },
  },
  permissions: [
    {
      level: 0,
      name: "User",
      check: () => true,
    },
    {
      level: 3,
      name: "Moderator",
      check: ({ guild, guildMember }: CheckPermissions) => {
        const modRole = guild.roles.cache.find(
          (r) => r.name.toLowerCase() === config.roles.modRole.name.toLowerCase()
        );

        if (modRole && guildMember.roles.cache.has(modRole.id)) {
            return true;
        } else {
          return false;
        }
      },
    },
    {
      level: 4,
      name: "Administrator",
      check: ({ guild, guildMember }: CheckPermissions) => {
        const adminRole = guild.roles.cache.find(
          (r) => r.name.toLowerCase() === config.roles.adminRole.name.toLowerCase()
        );
        if (adminRole && guildMember.roles.cache.has(adminRole.id)){ 
          return true;
        } else {
          return false;
        }
      },
    },
    {
      level: 5,
      name: "Server Owner",
      check: ({ author, channel, guild }: CheckPermissions) => {
        return channel.type === ChannelType.GuildText
          ? guild.ownerId === author.id
            ? true
            : false
          : false;
      },
    },
    {
      level: 8,
      name: "Bot Support",
      check: ({ author }: CheckPermissions) => {
        if (!config.support) {
          if (config.ownerID === author.id) {
            return true;
          } else {
            return false;
          }
        }

        return config.support.includes(author.id);
      },
    },
    {
      level: 9,
      name: "Bot Admin",
      check: ({ author }: CheckPermissions) => {
        if (!config.admins) {
          if (config.ownerID === author.id) {
            return true;
          } else {
            return false;
          }
        }

        return config.admins.includes(author.id);
      },
    },
    {
      level: 10,
      name: "Bot Owner",
      check: ({ author }: CheckPermissions) => {
        return config.ownerID === author.id;
      },
    },
  ],
};

module.exports = config;

Properties

ownerID string
Your discord user Id, you should define this in your .env file. Expected: process.env.OWNER_ID

admins string | Array<string>
The bot admin discord Ids, you should define this in your .env file.

support string | Array<string>
The bot support discord Ids, you should define this in your .env file.

prefix string | Array<string>
Define the call prefix for command calls that are not slash command calls. You can define this as an array or as a string

token string
Your Discord Bot Token, this token can be found in Discord Developer Portal. You should define this in your .env file. Expected: process.env.DISCORD_TOKEN

clientId string
Your bot client id, this id can be found in Discord Developer Portal > "General Information" > application id, you should define this in your .env file. Expected: process.env.CLIENT_ID

toDeleteSlashCommand string | true
If you want to delete a slash command by slash command Id, you can enter the slash command Id, or if you want to delete all the slash commands then enter the boolean: true

displayAdminCommandCallsByNonAdmin boolean
If you want to display an error message when a user who permissions level is less than 7 and uses an bot support or higher permission level command. Default is false.

roles Object
The role names of your permissions of all guild server this bot is in.

Property Type Description
modRole Roles The role name and role id(optional) of your moderator role of all guild server this bot is in; Default Permission level of 3.
adminRole Roles The role name of your administrator role of all guild server this bot is in; Default Permission level of 4.
k:string Roles You can define as many properties as needed and use them for any roles when customizing the permissions array.
Roles Type This type is a object that contains the following property.
Property Type Description
id
string The id of the role
name string The name of the role.

permissions Array<Object>
The Permissions level definitions

Property Type Description
level number The level property represents a numeric value.
name string The name property represents a string value.
check method The check method is a function that takes a parameter data of type CheckPermissions, which contains information about the author, guild, guildMember, channelType, and channel. It returns a boolean indicating whether the user has the required permission level.
CheckPermissions Type
Property Type Description
author User The author property represents the user who initiated the command.
guild Guild The guild property represents the server where the command was called.
guildMember GuildMember The guildMember property represents the member who called the command within the guild.
channel TextChannel | DMChannel The channel property represents the TextChannel or DMChannel where the command was called.
channelType ChannelType The channel type of the channel where the command was called.