Welcome to SDHandler

A package aimed at making sure that Discord bots are developed more easily !!

Stars Badge
Forks Badge
Pull Requests Badge
Issues Badge
Contributors Badge
LICENSE Badge

Introduction

This package was developed to make development of Discord bots using Discord.js package more easy. All the commands ( legacy and slash commands) , Events ( guild and client ) and Buttons are handled by this package. Thus no need to make a event/command handler !

Usage

So basically you start by cloning the package in your terminal/cmd

 git clone https://github.com/MihirBhave/sdhandler.git

Open your project and bring the package . Next , open your index.js (YOUR MAIN FILE) and import the package

    const sdhandler = require('./sdhandler')

Now lets use the package !

const sdhandler = require('./sdhandler')

sdhandler.sdhandler({
    client : client ,//Supply the Client Object 
    testOnly : true,  // Use true if you want to test the slash commands for the guild only 
    guildID : "YOUR-GUILD-ID" , // The GUILD ID if you have set testOnly to true
    commandsDir : "commands-path", // (Optional) The relative path to your commands folder. If nothing is provided ./commands will be taken by default
    eventsDir : "events-path" , // (Optional) The relative path to your events folder . If nothing is given ./events will be taken by default
    token : "YOUR-TOKEN" , // The token of your Bot
    prefix : "PREFIX" , // The prefix of your Bot (For Slash commands). Default is "!" 
    buttonsDir : "buttons-path" // (Optional) The relative path to your buttons folder. If nothing is given , ./buttons will be taken by default
})

Commands

Alright , So the setup for your bot to work is done. Now lets start test this package out. Go into your commands folder (The one which you supplied to the bot) and lets make a new file called as “ping.js”.

    module.exports = {
        name : 'ping', // The name of your command
        description : 'Replies with a pong !', // A brief description of what your command does
        permissions : [Permissions.FLAGS.SEND_MESSAGES] , // The permission you want the USER to have in order to run the command
        slash : true , // If you want this command to be a slash command as well set it to true.
        async execute({message , interaction}) {
            // CODE-HERE
        }
    }

The execute function consists of 5 parameters : args (Options of legacy commands) , message (Message Component of Legacy Command) , client(Client Object) , interaction (Interaction Componenent of a slash command) , options(The options of the slash command).

Lets run the execute function

    async execute({message , interaction }){ // Let us use the parameters we need
        if(message){ // If a Message Component is returned
            await message.reply({content "Pong ! "})
        }

        if(interaction){ // If a Interaction Component is returned
            await interaction.reply({content : 'Pong!' , ephemeral : true})
        }
    }

Events

Let us now test the events ! Go into your events folder , for this example lets make a file called “message.js” . This event will get triggered when someone sends a message in the guild/DM.

    module.exports = {
        name : 'messageCreate' , // Name of the event you want to listen to.
        async run(message) { 
            console.log(`${message.content}`)
        }
    }

Buttons

Now lets try the buttons. Navigate to your Buttons folder and create a nodeJS file.

    module.exports = {
        name : 'button-custom-ID' ,// The custom ID of the button 
        async run({client , interaction}){
            // Do whatever you want the button to do.
        }
    }

GitHub

View Github