I recently archived this repository because it was really hard to make it work on windows. So, I dropped it's support for windows. In future, I might add support for windows. But current you have to use WSL 2 to work to work on it on windows.
A complete discord.js
typescript handler. Automatically register commands and sub-commands.
- 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
andInteraction
triggers.
- 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
- Create
.env
file 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.
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
},
})
Autocomplete
interaction are handled byautocomplete
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
},
})
- You can set
permissions
property. It will automatically check permissions for you. - You can set custom
timeout
,dev
orbeta
,defer
andephemeral
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) {},
})
- You get
response
,warn
anderror
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)
},
})
- You can create a directory and put your commands directory in it to create
subcommand
andsubcommand-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 Menu
have two types in the context-menus (Users
andMessages
) directory.
- Every interaction handler has
permission
property for auto permission checking.
- You get
response
,warn
anderror
method for quickly replying to users. (same ascommands
)
Note:
autocomplete
interactions 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
| |__ file
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")
},
})
You can save logs using Discord Webhook
.
- Set your
Discord Webhook
URL asenvironment
variable. - Check
environment
variable part in installation.