This was my first project that I was truly happy with. However, I no longer have the mental capacity to maintain this repository. Why? Breaking changes. I still remember trying to update a single package and spending five hours fixing type errors. Additionally, discord.js is notorious for its breaking changes, and I don't believe they will stop finding new ways to break users' code.
A complete discord.js typescript handler. Automatically register commands and sub-commands.
- Dynamic handler. You don't have to use
client.onin your index file. - Creates sub commands from directory name for handling them from different module.
- Automatically register commands.
- Handle other [
Buttons,SelectMenu,Modal,ContextMenu] interactions. - Handle
MessageandInteractiontriggers.
- Use this command to clone the repository.
git clone https://github.com/3N147/Discord-handler.git cd Discord-handlerInstall all dependencies and start as dev. Using npm:
npm i npm run devor using yarn:
yarn yarn dev- Create
.envfile and set those following values. Take a look in the example file.DISCORD: Discord API TokenLOGIN: Discord Webhook URL for bot logging logsERROR: Discord Webhook URL for error logsGUILDS: Discord Webhook URL for guild join or leave logs
- All commands are categorized by directory in commands directory.
- You just have to export a commands object using the Command Class.
runmethod will be executed when someone uses the command.
import { Command } from "../../../structures/Command" export default new Command({ data: { name: "command-name", // The name of the command description: "A description", }, async run(interaction) { // Your code goes here }, })Autocompleteinteraction are handled byautocompletemethod. Learn More
Example
import { Command } from "../../../structures/Command" import { ApplicationCommandOptionType } from "discord.js" export default new Command({ data: { name: "autocomplete", description: "autocomplete example", options: [ { type: ApplicationCommandOptionType.String, name: "input", description: "Type anything for autocomplete.", autocomplete: true, required: true, }, ], }, async autocomplete(interaction, focused) { const choices = getChoicesSomeHow(focused) return choices }, async run(command) { return }, })- You can set
permissionsproperty. It will automatically check permissions for you. - You can set custom
timeout,devorbeta,deferandephemeralproperty.
Example
import { Command } from "../../../structures/Command" export default new Command({ data: { name: "ping", description: "ping pong" }, dev: true, beta: true, permissions: ["Speak"], deffer: true, ephemeral: true, timeout: 1000 * 5, // 5 seconds async autocomplete(interaction, focused) {}, async run(command) {}, })- You get
response,warnanderrormethod for quickly replying to users.
Example
import { Command } from "../../../structures/Command" export default new Command({ data: { name: "ping", description: "ping pong" }, async run(command) { command.response("Thanks for using me.") command.warn("You can't do that.", false, 5) command.error("User don't exists.", true) }, })- You can create a directory and put your commands directory in it to create
subcommandandsubcommand-group. Learn More
commands | |__ category-directory | |__ command-file "/ping" | |__ category-directory | |__ command-directory | |__ command-file "/help commands" | |__ category-directory | |__ command-directory | |__ subcommand-group-directory | |__ command-file "/timeout user remove"All Button, Select Menu, Modal and Context Menu handlers are available in the interactions directory.
Note:
Context Menuhave two types in the context-menus (UsersandMessages) directory.
- Every interaction handler has
permissionproperty for auto permission checking.
- You get
response,warnanderrormethod for quickly replying to users. (same ascommands)
Note:
autocompleteinteractions are handled from command handlers.
selectmenuInteraction has different types. [String, User, Role, Channel, Mentionable] There are different classes for different types of select menu.
It uses glob to find all module on a particular directory.
EXAMPLE OF VALID SELECT MENU HANDLERS select-menus | |__ directory | |__ file | |__ file | |__ directory | |__ directory | |__ fileIn Button, Select Menu and Modal Submit interaction there is customValue property.
Here is an example use case of this feature. This is a user filter.
import { Command } from "../../../structures/Command" // Command handler export default new Command({ data: {name: "create-button", description: "create a cool button"}, async run(interaction) { // customId = `${key}:${customValue}` const button = new ButtonBuilder()....setCustomId(`cool-button:${user.id}`) const components = [...(button)] interaction.reply({ components }) }, })import Button from "../../../structures/Button" // Button handler export default new Button({ id: "cool-button", // key async run(interaction) { // customValue if (interaction.customValue !== interaction.user.id) interaction.warn("You can't use this button") }, })You can save logs using Discord Webhook.
- Set your
Discord WebhookURL asenvironmentvariable. - Check
environmentvariable part in installation.