discord.handler.ts
Version:
a simple discord handler
92 lines (72 loc) • 1.6 kB
Markdown
```
npm i discord.handler.ts
```
```js
const { CommandsBuilder } = require("discord.handler.ts");
const app = new CommandsBuilder({
client: client,
eventsFolder: "./events",
commandsFolder: "./commands",
});
```
```js
const { Collection } = require('discord.js');
client.commands = new Collection();
app.loadEvents();
app.loadCommands();();
```
```js
module.exports = {
name: "<events name>",
execute(client) {
//Code
},
};
```
```js
const prefix = "!";
module.exports = {
name: 'messageCreate',
execute(message, client) {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(client, message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
},
}
```
```js
module.exports = {
name: 'ping',
async execute(message, args, client) {
message.channel.send("pong!")
}
}
```
<img src="https://cdn.discordapp.com/attachments/941006884880650280/1006891200600625232/unknown.png" alt="project photo">
```
1.1.1
```
```
SlashCommandBuilder
```
```
Ziad
```