Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
/ Discord-handler Public archive

A automatic Discord.js typescript handler. It automatically handles slash commands, event and other discord interactions.

License

Notifications You must be signed in to change notification settings

Nadim147c/Discord-handler

Repository files navigation

No Longer Maintained!

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.


Discord Handler

A complete discord.js typescript handler. Automatically register commands and sub-commands.

Features

  • Dynamic handler. You don't have to use client.on in 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 Message and Interaction triggers.


Installation

  • Use this command to clone the repository.
git clone https://github.com/3N147/Discord-handler.git
cd Discord-handler

Install all dependencies and start as dev. Using npm:

npm i
npm run dev

or using yarn:

yarn
yarn dev

Environment Variables

  • Create .env file and set those following values. Take a look in the example file.
    • DISCORD: Discord API Token
    • LOGIN: Discord Webhook URL for bot logging logs
    • ERROR: Discord Webhook URL for error logs
    • GUILDS: Discord Webhook URL for guild join or leave logs

Commands

  • All commands are categorized by directory in commands directory.
  • You just have to export a commands object using the Command Class.
  • run method 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
    },
})

Auto Complete

  • Autocomplete interaction are handled by autocomplete method. 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
    },
})

Properties

  • You can set permissions property. It will automatically check permissions for you.
  • You can set custom timeout, dev or beta, defer and ephemeral property.
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) {},
})

Methods

  • You get response, warn and error method 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)
    },
})

Subcommands and Files Structure

  • You can create a directory and put your commands directory in it to create subcommand and subcommand-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"

Interactions

All Button, Select Menu, Modal and Context Menu handlers are available in the interactions directory.

Note: Context Menu have two types in the context-menus (Users and Messages) directory.

Properties

  • Every interaction handler has permission property for auto permission checking.

Methods

  • You get response, warn and error method for quickly replying to users. (same as commands)

Note: autocomplete interactions are handled from command handlers.

Select Menus

selectmenuInteraction has different types. [String, User, Role, Channel, Mentionable] There are different classes for different types of select menu.

Files Structure

It uses glob to find all module on a particular directory.

EXAMPLE OF VALID SELECT MENU HANDLERS
select-menus
|
|__ directory
|   |__ file
|
|__ file
|
|__ directory
|   |__ directory
|       |__ file

Custom Value

In 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")
    },
})

Logging

You can save logs using Discord Webhook.

  • Set your Discord Webhook URL as environment variable.
  • Check environment variable part in installation.

License

Distributed under MIT license by Nadim147c.

About

A automatic Discord.js typescript handler. It automatically handles slash commands, event and other discord interactions.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy