npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord.js-core

v2.1.1

Published

Multi-functional library for discord.js bot

Downloads

15

Readme

discord.js-core

A simple bot handler for discord.js/v14

Features

  • Easy Application Commands (including easy AutoCompleters)
  • Easy Customizable MessagePages
  • Easy Actions (EmojiAction, ButtonAction, SelectMenuAction)
  • Easy to combine Actions and a message (called MessageCore)

Installation

Run npm install discord.js-core in the terminal.

Set-up

Create index.js file and edit it.

const { Core } = require("discord.js-core");

const core = new Core({

    /* discord.js client options */

    // MessageContent requires to be enabled on the application developer portal (https://discord.com/developers/applications/)
    intents: ["Guilds", "GuildMessages", "GuildMessageReactions", "MessageContent"],
    allowedMentions: { repliedUser: false }, // Disable mention on reply (Recommended)


    /* discord.js-core core options */

    prefix: "!", // message command prefix
    guildId: "Your Guild ID", // if not provided, your commands will be applied to global (to all guilds, DMs, and groups)
    token: "Your Token",
    // debug mode, which enables you to develop your bot more easily. (e.g. All commands have "dev-" at the head of their name in debug mode)
    // when `devMode` is true, `guildId` or `devGuild` must be provided.
    devMode: false,
});

core.login();

Run the index.js with node . or node index.js in the terminal, and you will find the bot is online.

Commands

You can handle SlashCommand, MessageCommand and ContextMenu in a single code.

Import the Command class

const { Command } = require("discord.js-core");
// or in ESM, import { Command } from "discord.js-core";

Code a command

Let's code your own command.

Here is an example of commands.

const command = new Command({
    name: "mention",
    description: "Mentions a user",
    messageCommandAliases: ["m"], // aliases for MessageCommand
    args: {
        "target": {
            type: ApplicationCommandOptionType.User,
            description: "The user to mention",
            required: true,
            messageCommand: true, // if this option is also for MessageCommand, set this to true; otherwise, set this to false
        },
    },
    supportsMessageCommand: true,
    supports: ["USER_CONTEXT_MENU", "SLASH_COMMAND"], // Types of commands which this command supports
    run: async (ic, args) => {
        // Type of ic is InteractionCore, which can combine Message and Interaction.
        // You can reply to Message or Interaction in the same method with InteractionCore.

        // If the interaction is from UserContextMenu, target id is in ic.contextMenuUser (If from MessageContextMenu, in ic.contextMenuMessage)
        const target = ic.contextMenuUser ?? args["target"];
        if (!target) return ic.reply({ content: "Target user not found" }); // Send reply message

        const mention = `<@${target.id}>`;
        await ic.reply({ content: mention }); // Send reply message
    },
});

This command enables users to mention a specific user by using slash command, message command, or context menu.

And DO NOT forget to register your commands.

core.addCommands(command);

Registering multiple commands from directory

You can also add commands from command directory.

Create "commands" folder, and a file for each command.

The contents of the file are as follows.

commands/test_command.js
const { Command } = require("discord.js-core");
module.exports = new Command(...);

// or in ESM
// import { Command } from "discord.js-core";
// export default new Command(...);

Register the commands in "commands" directory to core

core.addCommandsInDir("commands");

Apply to Discord (Adding Slash-Command and Context-Menu against Discord)

Apply registered commands with core.applyCommands().

core.login(() => core.applyCommands()); // login, and apply commands on ready

More examples available in example folder

See example folder for more examples!
And typescript example here!