# Bot

extends Client

Creates a bot client.

Properties
Methods
Events
  • commands
  • slashReady
  • restApi
  • defaultNoPerm
  • addCommand
  • addEvent
  • loadCommands
  • setDefaultNoPerm
  • init
  • commandsLoad

# Import

import { Bot } from 'discordkit';
const { Bot } = require('discordkit');

# Constructor

new Bot(config);
Parameter Type Description
config ClientOptions Options for the client

# Properties

# .commands

The bot's command collection.
Type: Collection<string, Command>


# .slashReady

Returns true if slash commands are loaded.
Type: boolean


# .restApi

@discord.js/rest
Type: REST


# Methods

# .defaultNoPerm(bot, interaction)

This function is executed if the command does not have the .noPerm() function.

Parameter Type Description
bot Bot Extended Discord.js client.
interaction CommandInteraction Slash command interaction.

Returns: Promise<any> | any


# .addCommand(command)

Adds commands to the bot.

Parameter Type Description
command Command | Command[] Command instance.

Returns: void

Example
const client = new Bot({ ... });

const ping = new Command({ ... });
const ban = new Command({ ... });

client.addCommand([ ping, ban ]);
/* or:
client.addCommand(ping);
client.addCommand(ban);
*/

# .addEvent(event)

Adds events to the bot.

Parameter Type Description
event Event | Event[] Event instance.

Returns: void

Example
const client = new Bot({ ... });

const onReady = new Event({ ... });
const onMessageCreate = new Event({ ... });

client.addEvent([ onReady, onMessageCreate ]);
/* or:
client.addEvent(onReady);
client.addEvent(onMessageCreate);
*/

# .loadCommands()

Sends commands to Discord.

Returns: Promise<void>

Example
const client = new Bot({ ... });

client.init('super-secret-token');

client.on('commandsLoad', async () => {
    const newCmd = new Command({ ... });
    client.addCommand(newCmd)
    await client.loadCommands();
    console.log('New command added.');
});

# .setDefaultNoPerm(callback)

Sets the default no authorization message.

Parameter Type Description
callback ICommand['noPerm'] No-Perm Function

Returns: void

Example
const client = new Bot({ ... });

client.setDefaultNoPerm(async (bot, interaction) => {
    await interaction.reply({
        content: 'not authorized'
    });
});

# .init(token)

It starts the bot and loads the commands.

Parameter Type Description
token string Bot Token

Returns: void

Example
import { Bot, Intents } from 'discordkit';

const client = new Bot({
    intents: [
        Intents.Guilds
    ]
});

client.init('super-secret-token');

# Events

# commandsLoad

It is triggered when commands are loaded after the bot is started.

Parameter Type Description
time number Loading time of commands.