1.2.2 • Published 3 years ago

nomad-slashcommands v1.2.2

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

npm NPM

Getting Started

Install nomad-slashcommands using npm:

console $ npm install nomad-slashcommands

Import nomad-slashcommands and create a command with response:

const Discord = require("discord.js");
const client = new Discord.Client();

const sc = require("nomad-slashcommands");
const SlashCommands = new sc.SlashCommands(client);

client.on("ready", () => {
    SlashCommands.setGuildID("guildID");
    
    // name, description
    const pingCommand = new sc.SlashCommand("ping", "Ping command description.");

    SlashCommands.addSlashCommand(pingCommand);
    
    pingCommand.events.on("execute", async (command) => {
        await SlashCommands.reply(command.interaction, "Pong!");
    });
})

client.login("TOKEN");

Example with options:

const Discord = require("discord.js");
const client = new Discord.Client();

const sc = require("nomad-slashcommands");
const SlashCommands = new sc.SlashCommands(client);

client.on("ready", () => {
    SlashCommands.setGuildID("guildID");
    
    // name, description
    const pingCommand = new sc.SlashCommand("ping", "Ping command description.");
    // name, description, required, type
    pingCommand.addOption("pong", "option description", false, 3);
    // Adding the slash command.
    SlashCommands.addSlashCommand(pingCommand);
    
    // Function called on execute:                      
    pingCommand.events.on("execute", async (command) => {
        if(command.args.pong){
            await SlashCommands.reply(command.interaction, "Pong!");
            return;
        }
        await SlashCommands.reply(command.interaction, "No pong, sorry..");
    });
})

client.login("TOKEN");

Values for the command variable (passed through the execute function)

  • interaction Object: Interaction data from the command.
  • args Object: Arguments passed through (options).
  • member GuildMember: Member variable (member that sent the command).
  • channel Channel: Channel the command was sent in.
  • guild Guild: Guild the command was sent in.

Functions from SlashCommands

  • setClient(client): Sets the client variable.
  • setGuildID(guildID): guildID doesn't have to be specified. If it is not, the command will be global (will take 1 hour max to update).
  • getCommands(): Returns all commands in a list.
  • getApp(): Returns the client API application.
  • getCommand(interaction): Returns the command name.
  • getOptions(interaction): Returns the options given from the interaction.
  • getUser(interaction): Returns the User object.
  • getMember(interaction): Returns the GuildMember object.
  • getChannel(interaction): Returns the Channel object.
  • getGuild(interaction): Returns the Guild object.
  • addSlashCommand(slashCommand): Adds SlashCommand to the database.
  • reply(interaction, response): Reply to the interaction with either a string or an MessageEmbed.
  • createAPIMessage(interaction, content): Creates the API content for the reply function. Doesn't need to be called but accessable.
  • deleteCommand(commandID): Deletes a SlashCommand.
1.2.2

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.0.9

3 years ago

1.1.7

3 years ago

1.0.8

3 years ago

1.1.6

3 years ago

1.0.7

3 years ago

1.1.5

3 years ago

1.0.6

3 years ago

1.1.4

3 years ago

1.0.5

3 years ago

1.1.3

3 years ago

1.0.4

3 years ago

1.2.1

3 years ago

1.1.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago