#
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);
#
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
)
bot
, interaction
)This function is executed if the command does not have the .noPerm() function.
Returns: Promise<any> | any
#
.addCommand(command
)
command
)Adds commands to the bot.
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
)
event
)Adds events to the bot.
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
)
callback
)Sets the default no authorization message.
Returns: void
Example
const client = new Bot({ ... });
client.setDefaultNoPerm(async (bot, interaction) => {
await interaction.reply({
content: 'not authorized'
});
});
#
.init(token
)
token
)It starts the bot and loads the commands.
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.