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

dcjs-util

v0.3.12

Published

Contains necessary shortcuts for discord.js

Downloads

16

Readme

Alisa Logo

Package Name Package size Version License

NPM

Source file

Creator(s)

Social media accounts

How to download?

  • First we create a node.js file (If you have not downloaded node.js to computer before, you can download node.js by clicking here)

  • Then we open the PowerShell terminal by "shift + right click" on the folder of the file you created.

Opening the PowerShell terminal

  • Then we write npm i dcjs-util and press enter.

  • Download the dcjs-util module

  • And now we have downloaded the dcjs-util module, congratulations 🎉🎉

What is this module?

  • This module allows you to easily use commands using the discord.js library

  • It increases the performance of your bot by making discord.js more performant than commands in some commands

  • Moreover, we add comment lines so that you can understand the commands so that you can edit the commands

  • This module was made with the sole purpose of helping people, without generating any income

So how to use?

It's very simple, first you have to open your discord bot file and write the following in it:

Taking and giving roles

const DiscordUtils = require("dcjs-util");
const memberRoleId = "12345678901234567";

client.on("messageCreate", async (message) => {
  // If user is bot
  if (message.author.bot) return;

  if (message.content.toLowerCase() == "!role") {
    const member = message.member;

    // If user doesn't have member role
    if (!DiscordUtils.hasRole(member, memberRoleId)) {
      try {
        // Add role
        await DiscordUtils.addRole(member, memberRoleId);

        return message.reply({
          content: `Successfully added role <@&${memberRoleId}>!`,
          allowedMentions: {
            repliedUser: true,
            roles: [],
          },
        });
      } catch (error) {
        // If an error occurred
        console.log(error);
        message.reply("Something went wrong!");
      }
    }
    // If user has member role
    else {
      try {
        // Remove role
        await DiscordUtils.removeRole(member, memberRoleId);

        return message.reply({
          content: `Successfully removed role <@&${memberRoleId}>!`,
          allowedMentions: {
            repliedUser: true,
            roles: [],
          },
        });
      } catch (error) {
        // If an error occurred
        console.log(error);
        message.reply("Something went wrong!");
      }
    }
  }
});

Count role, channel, member or user

const DiscordUtils = require("dcjs-util");

client.on("messageCreate", async (message) => {
  // If user is bot
  if (message.author.bot) return;

  if (message.content.toLowerCase().startsWith("!countrole")) {
    // Capture the roles she/he tagged or entered the ID in the message
    const allRoles = DiscordUtils.fetchRolesInContent(
      message.guild,
      message.content
    );

    return message.reply(
      `You mentioned exactly ${DiscordUtils.toHumanize(
        allRoles.size
      )} roles in your message`
    );
  } else if (message.content.toLowerCase().startsWith("!countchannel")) {
    // Capture the channels she/he tagged or entered the ID in the message
    const allChannels = DiscordUtils.fetchChannelsInContent(
      message.guild,
      message.content
    );

    return message.reply(
      `You mentioned exactly ${DiscordUtils.toHumanize(
        allChannels.size
      )} channels in your message`
    );
  } else if (message.content.toLowerCase().startsWith("!countmember")) {
    // Capture the members she/he tagged or entered the ID in the message
    const allMembers = DiscordUtils.fetchMembersInContent(
      message.guild,
      message.content
    );

    return message.reply(
      `You mentioned exactly ${DiscordUtils.toHumanize(
        allMembers.size
      )} members in your message`
    );
  } else if (message.content.toLowerCase().startsWith("!countuser")) {
    // Capture the users she/he tagged or entered the ID in the message
    const allUsers = DiscordUtils.fetchUsersInContent(
      message.guild,
      message.content
    );

    return message.reply(
      `You mentioned exactly ${DiscordUtils.toHumanize(
        allUsers.size
      )} users in your message`
    );
  }
});

Seng guild infos

const DiscordUtils = require("dcjs-util");

client.on("messageCreate", async (message) => {
  if (message.author.bot) return;

  if (message.content.toLowerCase() == "!serverinfo") {
    const guildInfos = await DiscordUtils.guildInfo(message.guild);

    const embed = new Discord.EmbedBuilder()
      .setAuthor({
        name: guildInfos.name,
        iconURL: guildInfos.iconURL ?? null,
      })
      .setDescription(
        `**• Created Date:** <t:${Math.floor(
          guildInfos.createdTimestamp / 1000
        )}:R>`
      )
      .addFields(
        {
          name: "GUILD INFORMATION",
          value:
            `🆔 **ID:** ${guildInfos.id}\n` +
            `👥 **Member Count:** ${DiscordUtils.toHumanize(
              guildInfos.memberCount
            )}\n` +
            `🎨 **Icon:** ${
              guildInfos.iconURL
                ? `[Icon Link](${guildInfos.iconURL})`
                : `~~[Icon Link]~~`
            }\n` +
            `🖼️ **Banner:** ${
              guildInfos.bannerURL
                ? `[Banner Link](${guildInfos.bannerURL})`
                : `~~[Banner Link]~~`
            }`,
          inline: true,
        },
        {
          name: "OTHER INFORMATION",
          value:
            `📅 **Created Date:** <t:${Math.floor(
              guildInfos.createdTimestamp / 1000
            )}:D>\n` +
            `🌍 **Region:** ${guildInfos.preferredLocale}\n` +
            `🚀 **Verification Level:** ${guildInfos.verificationLevel}`,
          inline: true,
        },
        {
          name: "CHANNELS & ROLES",
          value:
            `📚 **Channels:** ${guildInfos.channels.size}\n` +
            `✏️ **Text Channel:** ${guildInfos.textChannels.size}``🔒 **Roles:** ${guildInfos.roles.size}`,
          inline: true,
        },
        {
          name: "FEATURES",
          value: `${guildInfos.features
            .map((feature) => `• ${feature}`)
            .join("\n")}`,
          inline: false,
        }
      )
      .setThumbnail(guildInfos.iconURL ?? null)
      .setColor("Random")
      .setTimestamp();

    return message.reply({
      embeds: [embed],
    });
  }
});

Send bot infos

const DiscordUtils = require("dcjs-util");

client.on("messageCreate", async (message) => {
  // If user is bot
  if (message.author.bot) return;

  if (message.content.toLowerCase() == "!botinfo") {
    const botInfos = await DiscordUtils.botInfo(message.client.user);

    // Read memory
    function readMemory(usedMemory) {
      function baytToMegabayt(number, fixed = 0) {
        return (number / 1024 / 1024).toFixed(fixed);
      }
      function baytToGigabayt(number, fixed = 1) {
        return (number / 1024 / 1024 / 1024).toFixed(fixed);
      }

      const gigabayt = baytToGigabayt(usedMemory);
      // If the used memory is greater than or equal to 1 GB, return the used memory in GB
      return gigabayt >= 1
        ? `${gigabayt} GB`
        : `${baytToMegabayt(usedMemory)} MB`;
    }

    // Create an embed
    const embed = new Discord.EmbedBuilder()
      .setAuthor({
        name: botInfos.globalName,
        iconURL: botInfos.displayAvatar,
      })
      .setDescription(
        `**• Last reboot:** <t:${Math.floor(botInfos.readyTimestamp / 1000)}:R>`
      )
      .addFields(
        {
          name: "BOT INFORMATION",
          value:
            `✏️ **My username:** ${botInfos.name}\n` +
            `🆔 **Discord ID:** ${botInfos.id}\n` +
            `📅 **My founding date:** <t:${Math.floor(
              botInfos.createdTimestamp / 1000
            )}:F>\n` +
            `🎚️ **RAM usage:** ${readMemory(botInfos.usedMemory)} - %${
              botInfos.usedMemoryPercentage
            }`,
          inline: true,
        },
        {
          name: "MY DELAY INFORMATION",
          value: `📡 **Bot's main delay:** ${botInfos.ping} ms`,
          inline: true,
        },
        {
          name: "SERVER INFORMATION",
          value:
            `💻 **Number of servers:** ${DiscordUtils.toHumanize(
              botInfos.guildCount
            )}\n` +
            `👥 **Number of users:** ${DiscordUtils.toHumanize(
              botInfos.userCount
            )}\n` +
            `🎞️ **Number of channels:** ${DiscordUtils.toHumanize(
              botInfos.channelCount
            )}\n` +
            `🏷️ **Number of roles:** ${DiscordUtils.toHumanize(
              botInfos.roleCount
            )}\n` +
            `🎉 **Number of emojis:** ${DiscordUtils.toHumanize(
              botInfos.emojiCount
            )}`,
          inline: true,
        },
        {
          name: "VERSIONS",
          value:
            `🎛️ **Node.js version:** ${process.version}\n` +
            `🔨 **Discord.js version:** v${Discord.version}`,
          inline: true,
        },
        {
          name: "VDS INFORMATION",
          value:
            `🎞️ **CPU:** ${botInfos.cpuName}\n` +
            `🔋 **Total ram:** ${readMemory(
              botInfos.totalMemory
            )} (**Free:** ${readMemory(botInfos.freeMemory)})`,
        }
      )
      .setThumbnail(botInfos.displayAvatar)
      .setColor("Random")
      .setTimestamp();

    // Send the embed
    return message.reply({
      embeds: [embed],
    });
  }
});

By typing this you can access all commands of the module!

So why dcjs-util?

  • The first reason is that it is overly simple and less likely to fail

  • The second reason is that since it is an open source module, it can be edited in a special way if you want

  • The third reason is that we are improving this module every day, making it more performance and adding new features to our strength

  • The fourth reason is... Well, I guess there's no other reason :( Maybe it's just to make me happy 👉👈

Please do not forget to use it in the latest version for more stable and performance of the module!

And finally

  • If you want to support this module, if you request me on github, I will be happy to help you.

  • Thank you for reading this far, i love you 💗

  • See you in my next modules!

lovee