1.0.3 • Published 1 year ago

djs-command-deployer v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

djsCommandDeployer

A simple, easy to use module that houses a Discord Client class that has two additional functions that can create, update and delete global and guild specific commands for your Discord App.

Installation

npm install git+ssh://git@github.com:The-LukeZ/djsCommandDeployer.git
npm install djs-command-deployer

Usage

Folder structure

The src folder it can be any folder. Just the commands folder should be a subfolder of the directory your index.js is located in.

Example:

📂src
 ┣ 📄index.js
 ┗ 📂commands
   ┗📂utility
     ┣ 📄ping.js
     ┗ 📄your-private-command.js

The command file

Note that for using this you need to install discord.js!

Key nameDescriptionDefault
ignoreIf set to true then this command will be ignored upon refreshingfalse
guildIdsAn Array of guild ids in which the command should be registered/updated ; command is global if not set[]
dataThe raw command data Learn more about it here-
runThe function to call (It's only important for your own logic - so name this whatever you want)-

- means that it doesn't have a default value

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
    ignore: true,
    guildIds: ["123456789", "987654321"], // Note: This wont automatically delete them from guilds!
    data: new SlashCommandBuilder()
        .setName("ping")
        .setDescription("Replies with Pong!"),

    // The function to call whenever the command is executed (Doesnt matter when calling client.deployCommands())
    async run(interaction) {
        await interaction.reply("Pong!");
    },
};

Deploy the commands

const { Events, GatewayIntentBits } = require("discord.js");
// Name it whatever you want
const Client = require("djs-command-deployer");
const { join: pathJoin } = require("node:path");
require("dotenv").config();

// Set up your client ; use the guide for example (https://discordjs.guide/creating-your-bot/main-file)

// Create a new client instance
let client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once).
client.once(Events.ClientReady, (readyClient) => {
    console.log(`Ready! Logged in as ${readyClient.user.tag}`);

    // Call deployCommands to refresh your commands
    readyClient.deployCommands(
        pathJoin(__dirname, "commands", "utility")
        // Optional: logOptions object
    );
});

// Log in to Discord with your client's token
client.login(process.env.DISCORD_TOKEN);

Delete a guild-command

There are two options to do this: Either with the command's ID or his name.

In this example we are building a manager-command that has StringOptions for the command and the guild id where one can paste in the ID or the name.\

Please see the example code for the command file and the index.js on how to do this in general.

logOptions

Option nameDescription / ExampleDefault
statusLogs like Started refreshing X global commandstrue
ignoredLogs like Command 'user' ignoredtrue
createdLogs like Created 'user'true
updatedLogs like Updated 'user'true
deletedLogs like Deleted 'user'true
noLogsNo logs at all (besides errors)false

TODO

  • L94 | Fix that currentCommands is correct (currently doesn't work and therefore checking for current commands doesn't really work)

  • L166 | Add support for sharding

  • Finish this.deleteCommand

Feel free to help me with the TODOs, I will merge any useful pull requests :)

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.9.3

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago