djs-command-handler
Simple command handler for discord.js
繁體中文
Install
run this in your terminal
npm i @gary50613/discord.js-command-handler
Test
npm i
npm test
✨ Features
- easy to set up
- works perfectly with discord.js
- ratelimit support
- error handling with event
- event listening
- commands group support
- SLASH COMMAND SUPPORT (beta)
Usage
JavaScript
basic how to initialize with options
const Discord = require('discord.js')
const ping = require("./commands/ping")
const bot = new Discord.Client()
require("@gary50613/djs-command-handler")(bot, {
prefix: '.',
})
bot.commands.loadCommands("./commands")
bot.commands.register(new ping())
bot.commands.register(new ping(), ..., ...)
bot.commands.on("dm", (m) => {
m.channel.send("u can only use command in a guild!")
})
bot.login(process.env.TOKEN)
make a command
const { Command } = require("@gary50613/djs-command-handler")
class Ping extends Command {
constructor() {
super(
"ping",
"ping the bot",
".ping",
"general",
["pong"]
);
}
async execute(bot, message, args, member, guild) {
message.reply('pong!')
}
}
module.exports = Ping
TypeScript
basic how to initialize with options
import { Client } from "discord.js"
import init from "@gary50613/discord.js-command-handler"
import ping from "./commands/Ping"
const bot = new Client()
init(bot, {
prefix: ".",
})
bot.commands.loadFolder("./commands")
bot.commands.register(new ping())
bot.commands.register(new ping(), ..., ...)
bot.commands.on("dm", (m) => {
m.channel.send("u can only use command in a guild!")
})
bot.login(process.env.TOKEN)
make a command
import { Command } from "@gary50613/discord.js-command-handler";
import { Client, Guild, GuildMember, Message } from "discord.js";
export default class Ping extends Command {
public constructor() {
super(
"ping",
"ping the bot",
".ping",
"general",
["pong"]
);
}
public async execute(bot: Client, message: Message, args: string[], member: GuildMember, guild: Guild) {
message.reply("pong!")
}
}
Event
type | description | parameter |
---|
dm | user execute a command in dm | Message |
ratelimit | user get ratelimited | Millisecond, Message |
execute | command successfully executed | Command, Message |
error | command execute error | Error, Command, Message |
promiseError | promise rejection | Error, Command, Message |
Reference
options
{
ratelimit: {
enable: false,
interval: 5000,
bypass: {
users: [],
permissions: ["ADMINISTRATOR"],
roles: []
}
},
prefix: "PREFIX",
dm: false,
bot: false
}
Author
🧑💻 Kane
❤️ Contributing
Feel free to open issue
or join my discord server