![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
djs-slash is a command handler for discord.js v13 that provides an easy command definition with file.
Features:
Install by running this command:
npm i djs-slash
discord.js
v13 is also required.
Project architecture example
├ commands/ (this folder contains all commands)
| ├ slash/ (slash command)
| | ├ ping.ts
| | └ cmd/
| | ├ subcommand.ts
| | └ subcommandgroup/
| | └ subcommand.ts
| ├ user/ (context menu commands on user)
| | ├ hi.ts
| | └ ban.ts
| └ message/ (context menu commands on message)
| ├ delete.ts
| └ repeat.ts
└ index.ts
const commands = SlashCommandManager.create({
commandFolder: './commands' // This is the path to the folder where command are stored relative to the entry point of the application (ie the index.ts file)
});
// If no parameter is provided, './commands' is used as default path
const commands = SlashCommandManager.create();
import { Client, Intents } from "discord.js";
import { SlashCommandManager } from "djs-slash";
const GUILD_ID = '000000000000000000'
const BOT_TOKEN = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
// Create the djs client
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// Load all commands from ./commands/
const commands = SlashCommandManager.create();
client.once("ready", async (client) => {
// Registering commands on a guild
const guild = await client.guilds.fetch(GUILD_ID);
await guild.commands.set(commands.toApplicationCommandData());
// Registering commands globally
await client.application.commands.set(commands.toApplicationCommandData());
});
client.on("interactionCreate", async (interaction) => {
// Pass the interaction to the SlashCommandManager to execute the command
if (await commands.execute(interaction)) {
// The interaction trigger a command
} else {
// The interaction didn't trigger a command.
// Either the interaction is not a command interaction
// either it didn't correspond to a registred command.
}
});
(async () => {
await client.login(BOT_TOKEN);
})();
Slash command files must be placed in a sub-folder named slash
inside the command folder.
The name of the file is the name of the command.
To create sub-command and sub-command group use folder. Folder name is the name of the command/group.
ping example:
import { SlashCommand } from 'djs-slash';
export default SlashCommand.define("Reply with 'pong'", {}, async (interaction) => {
await interaction.reply({ content: ':ping_pong: pong !', ephemeral: true });
});
import { SlashCommand } from "djs-slash";
// Use SlashCommand.define to create your command
// The value must be exported with `export default`
export default SlashCommand.define(
"Reply with 'pong'", // The description of the command
{
defaultPermission: true, // (optionnal) the defaultPermission option
// The arguments of the command
options: {
// Create a argument named 'foo'
foo: {
type: "STRING",
description: "The foo argument",
required: true,
choices: [
{ name: "ping", value: "Ping" },
{ name: "pong", value: "Pong" },
] as const, // `as const` is required to resolve properly the type of the argument.
},
// Create a argument named 'bar'
bar: {
type: "USER",
description: "A user to mention",
},
},
},
// The callback of the function
// The first parameter is the CommandInteraction
// The second parameter is an object with the value of the argument
async (interaction, { foo, bar }) => {
// The type of the arguments are deduced from the value of `type` above.
// If the argument is not required (by default) the value can be null.
// foo : "Ping" | "Pong"
// bar : User | null
await interaction.reply(`:ping_pong: ${foo} !` + bar ? ` ${bar}` : "");
},
);
SlashCommand.define(description, options, callback)
description
string
: the description of the command.options
{ defaultPermission, options }
defaultPermission
boolean
: whether the command is enabled by default when the app is added to a guild.options
object
: the options of the command, key is the name of the options.
description
string
: the description of the option.required
boolean
: whether the option is required.type
: the type of the option.choices
: the choices of the option for the user to pick from.channelTypes
: when the option type is channel, the allowed types of channels that can be selected.callback
(interaction, options) => void | Promise<void>
interaction
CommandInteraction
: the interaction object that trigger the command.options
object
: a key-value object where key is the name of the option and the value the value provided by the user.User command files must be placed in a sub-folder named user
inside the command folder.
The name of the file is the name of the command.
An user command example:
import { UserCommand } from 'djs-slash';
export default UserCommand.define(async (interaction, user) => {
await interaction.reply({ content: `Hi, ${user}` });
});
UserCommand.define(callback)
callback
(interaction, user) => void | Promise<void>
interaction
ContextMenuInteraction
: the interaction object that trigger the command.user
User
: the target of the command.Message command files must be placed in a sub-folder named message
inside the command folder.
The name of the file is the name of the command.
A message command example:
import { MessageCommand } from 'djs-slash';
export default MessageCommand.define(async (interaction, message) => {
await interaction.reply({ content: message.content });
});
MessageCommand.define(callback)
callback
(interaction, message) => void | Promise<void>
interaction
ContextMenuInteraction
: the interaction object that trigger the command.user
Message
: the target of the command.Checkout the example project to learn more.
To run the example project:
git clone https://github.com/tguichaoua/djs-slash.git
cd djs-slash
npm ci
npm run build
cd example
config.jsonc
, name it config.json
and fill it upnpm start
👤 Tristan Guichaoua
Copyright © 2021 Tristan Guichaoua.
This project is MIT licensed.
FAQs
An application command handler for discord.js v13
The npm package djs-slash receives a total of 0 weekly downloads. As such, djs-slash popularity was classified as not popular.
We found that djs-slash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.