#Bot

extends Client

Creates a bot client.


#Import

import { Bot } from 'discordkit';

#Constructor

new Bot(config);
ParameterTypeDescription
configClientOptions Options for the client

#Properties

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


Returns true if slash commands are loaded.
Type: boolean


@discord.js/rest
Type: REST


#Methods

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

ParameterTypeDescription
botBotExtended Discord.js client.
interactionCommandInteraction Slash command interaction.

Returns: Promise<any> | any


Adds commands to the bot.

ParameterTypeDescription
commandCommand | 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); */

Adds events to the bot.

ParameterTypeDescription
eventEvent | 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); */

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.'); });

Sets the default no authorization message.

ParameterTypeDescription
callbackICommand['noPerm']No-Perm Function

Returns: void

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

It starts the bot and loads the commands.

ParameterTypeDescription
tokenstringBot Token

Returns: void

Example
import { Bot, Intents } from 'discordkit'; const client = new Bot({ intents: [ Intents.Guilds ] }); client.init('super-secret-token');

#Events

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

ParameterTypeDescription
timenumberLoading time of commands.