A discordjs package that provide you with util functions and classes to help speed up your development
npm install @devspeed/discord-clientjs
const { Loaders, RecursiveLoader, resgisterGuildCommand } = require("@devspeed/discord-client");
const { Client } = require("discord.js");
const client = new Client({
intents: ["Guilds"]
});
Loaders.loadEvents(__dirname, { directory: "./events", client })
const { collection, JsonData } = RecursiveLoader.loadSlashCommands(__dirname, { directory: "./slash" });
// returns a collection
const messageCommand = RecursiveLoader.loadMessageCommands(__dirname, { directory: "commands" })
client.slashCommands = collection;
client.messageCommand = messageCommand;
console.log(client.slashCommands)
console.log(client.messageCommand)
resgisterGuildCommand({
clientId: 'client id goes here',
guilldId: 'guilid id goes here',
token: "token goes here",
commands: JsonData, // the slash command loader already returns the collection and the jsonData
})
client.login("token goes");
`
The recursive loader will load every file in the specified directory, regardless of how deeply nested it is within your folder structure.If you prefer not to load every file in the specified directory, you can opt to use a regular loader instead see below for example
`js
const { Loaders } = require("@devspeed/discord-client");
const collection = Loaders.loadSlashCommand(__dirname, { directory: '/slash'});
`
$3
`js
Loaders.loadSlashCommand(__dirname, {
directory: '/slash',
filter: (file) => file.endsWith(".js") || file.endsWith("ts"), // the default value when filter is undefined
});
`
To extract the exported data object from only certain files within the specified directory, you can use the filter function. This function takes the currently iterated file as a parameter and returns a boolean value. If the boolean is true, the exported data object will be extracted.
$3
`js
const { SlashCommand } = require("@devspeed/discord-client")
const { SlashCommandBuilder } = require('discord.js');
module.exports = new SlashCommand({
data: new SlashCommandBuilder()
.setName("help")
.setDescription("help command"),
async execute(client, interaction) {
await interaction.reply("pong");
}
})
`
$3
`js
const { MessageCommand } = require("@devspeed/discord-client");
module.exports = new MessageCommand({
name: "ping",
description: "A simple pong command",
cooldown: 10,
category: "general",
enabled: true,
execute: (client, message, args) => {
console.log(client, message, args)
}
})
`
$3
`js
const { EventHandler } = require("@devspeed/discord-client");
module.exports = new EventHandler({
name: "ready",
execute(client, interaction) {
/// console.log(logined in as ${client.user.tag});
console.log(client.user)
}
})
``