dsc

djs-slash-commands

A wrapper meant to incorporate discord.js slash commands into your Discord bot

Showing:

Popularity

Downloads/wk

12

GitHub Stars

7

Maintenance

Last Commit

2mos ago

Contributors

1

Package

Dependencies

1

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Discord.js Slash Commands!

A wrapper meant to incorporate discord.js slash commands into your Discord bot.

Installation

$ npm i --save djs-slash-commands

Usage

Required:

Importing and initializing the handler:

const { SlashCommandHandler } = require("djs-slash-commands");
client.SlashCommands = new SlashCommandHandler(client);

Receiving the interaction:

Note: You must reply in 3 seconds. To get past this limit, defer the interaction, or use followUps.

client.on("slashCreate", async (interaction) => {
  if (interaction.commandName === "somecommand")
    return interaction.reply("Some reply...");
  if (interaction.commandName === "someothercommand")
    return interaction.reply("This is an ephemeral.", { ephemeral: true });

  // Sending a followup message:
  if (interaction.commandName === "ping") {
    interaction.reply("Ping?!");
    interaction.followUp("Pong!");
  }

  // Editing & deleting reply.
  if (interaction.commandName === "thatonecommand") {
    await interaction.reply("REPLIED?!");
    await interaction.editReply("EDITED?!");
    // DELETED?!
    interaction.deleteReply();
  }

  // Deferring an interaction. Makes it say "{Name} is thinking..." and gives you 15 minutes to reply.
  if (interaction.commandName === "defer") {
    interaction.defer();
    setTimeout(
      async () => await interaction.reply("I have stopped thinking."),
      9000
    );
  }
});

Global Commands:

Option Types:
NameValue
SUB_COMMAND1
SUB_COMMAND_GROUP2
STRING3
INTEGER4
BOOLEAN5
USER6
CHANNEL7
ROLE8
MENTIONABLE9
Base Object:
const baseObject = {
  name: "ping",
  description: "Pong?!",
};

// Or, with options:

const baseObject = {
  name: "ping",
  description: "pong?!",
  options: [
    {
      name: "someoption",
      description: "some description",
      type: "USER",
    },
  ],
};

client.slashCommands.add(baseObject);

Bulk adding global slash commands:

Warning: This removes all other slash commands your bot has.

const baseObject2 = {
  name: "othercommand",
  description: "ANOTHER COMMAND?!",
};
client.SlashCommands.bulkAdd([baseObject, baseObject2]);

Guild-Specific Commands:

client.SlashCommands.add(baseObject, "GuildID");

Bulk add guild-specific slash commands:

Warning: This removes all other slash commands..

client.SlashCommands.bulkAdd(
  [baseObject, baseObject2]
  "GuildID"
);

Viewing/Deleting the Command:

client.on("ready", async () => {
  /**
   * Viewing the command(s).
   */

  const cmds = await client.SlashCommands.get();
  console.log(cmds); // Logs all slash commands.

  // Guild Commands:
  const guildCmds = await client.SlashCommands.get(null, "GuildID");
  console.log(guildCmds); // Logs all guild commands.

  // For the following methods, you must get the ID. You can do so by using the methods above, as they all return a command object with the property ID.

  // For specific commands:
  const cmd = await client.SlashCommands.get("ID");
  console.log(cmd);

  // For guild-specific commands:
  const guildCmd = await client.SlashCommands.get("ID", "GuildID");
  console.log(guildCmd);

  /**
   * Deleting the command(s).
   * For the following methods, you must get the ID. You can do so by using the methods above, as they all return a command object with the property ID.

   */

  // Global command:
  await client.SlashCommands.delete("ID");

  // Guild-Specific command:
  await client.SlashCommands.delete("ID", "GuildID");
});

Interaction Properties:

NameValuePurpose
clientDiscord.ClientClient that initiated the interaction.
typeBooleanInteraction type.
isCommandBooleanWhether interaction is a command.
channelDiscord.TextChannelChannel interaction occured in.
channelIDStringChannel interaction occured in's ID.
guildDiscord.GuildGuild the interaction occured in.
guildIDStringGuild the interaction occured in's ID.
memberDiscord.GuildMemberGuild member who used the interaction. null if in DMs.
memberIDStringGuild member who used the interaction's ID. null if in DMs.
commandNameStringInteraction command name.
commandIDStringInteraction command ID.
authorDiscord.UserUser who used interaction.
authorIDStringUser who used the interaction's ID.
optionsDiscord.CollectionArguments provided for interaction.
idStringInteraction ID.
createdDateDjsSlashCommands.Timestamp (custom class)When the interaction was created's date.
createdTimestampEpochNumberWhen the interaction was created, relative to Discord's Epoch.
createdTimestampDateWhen the interaction was created's timestamp.
tokenStringInteraction token.
applicationIDStringInteraction application ID.
webhookDiscord.WebhookClientWebhook client for sending followup messages.
repliedBooleanWhether the interaction has been replied to.
deferredBooleanWhether the interaction has been deferred to.
rawObjectRaw interaction object returned from the API.

Application Command Properties

NameValuePurpose
nameStringCommand name.
idStringCommand ID.
clientStringClient that initiated the command.
applicationIDStringCommand application ID.
descriptionStringCommand description.
optionsArrayCommand options.
versionStringCommand version.
guildIDStringCommand Guild ID. null if global command.
guildDiscord.GuildCommand Guild. null if global command.
createdTimeDjsSlashCommands.TimestampInteraction created time object. (Custom class)
createdTimestampDateCommand creation timestamp.
createdTimestampEpochNumberCommand creation timestamp, relative to Discord's epoch.
defaultPermissionsBooleanWhether the command will be added when the client is added to a new guild.
typeNumberCommand type.
SlashCommandHandlerDjsSlashCommands.SlashCommandHandlerSlash command handler that initiated this command.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100