easy discord.js commandHandler
- this is use for discord.js@14
- Required by node.js 16.9.0 or higher
- Stable version
npm i discommand- Devlopment version
npm i discommand@nextindex.ts
import { DiscommandClient, LoadType } from 'discommand'
import { GatewayIntentBits } from 'discord.js'
const client = new DiscommandClient(
{
intents: [GatewayIntentBits.Guilds],
},
{
loadType: LoadType.File,
directory: {
command: __dirname + '/commands',
},
}
)
client.loadAll()
client.login('your_bot_token')commands/ping.ts
import { Command } from 'discommand'
import { ChatInputCommandInteraction, ApplicationCommandType } from 'discord.js'
export default class extends Command {
constructor() {
super()
this.name = 'ping'
this.description = 'Pong'
this.type = ApplicationCommandType.ChatInput
}
execute(interaction: ChatInputCommandInteraction) {
interaction.reply('Pong!')
}
}index.js
const { DiscommndClient, LoadType } = require('discommand')
const { GatewayIntentBits } = require('discord.js')
const path = require('path')
const client = new DiscommandClient(
{
intents: [GatewayIntentBits.Guilds],
},
{
loadType: LoadType.File,
directory: {
command: __dirname + '/commands',
},
}
)
client.loadAll()
client.login('your_bot_token')commands/ping.js
const { Command } = require('discommand')
const { SlashCommandBuilder, ApplicationCommandType } = require('discord.js')
module.exports = class extends Command {
constructor() {
super()
this.name = 'ping'
this.description = 'Pong!'
this.type = ApplicationCommandType.ChatInput
}
execute(interaction) {
interaction.reply('Pong!')
}
}