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-additions

v1.0.1

Published

Package to make easier discord bot developpement in Javascript

Downloads

1

Readme

discord.js-additions

Package to make easier discord bot developpement in Javascript

Getting Started

Instalation

Using npm

$ npm install discord.js-additions

Import

// ES6
import * as DiscordAdditions from 'discord.js-additions';

// CommonJS
const DiscordAdditions = require('discord.js-additions');

Handlers

Command Handler

Creating the CommandHandler

const commandHandler = new DiscordAdditions.CommandHandler(client, '!');
// client is your Discord.Client
// '!' is the prefix used for every commands added in this handler

Creating a HandledCommand

const handledCommand = new DiscordAdditions.HandledCommand('hello', hello);
function hello(client, message, args) {
  message.reply('Hello!');
}
// 'hello' is the name of the command -> The command will be !hello
// hello is callback function (the code executed when the command will be triggered)

Adding the HandledCommand to the CommandHandler

commandHandler.addHandledCommand(handledCommand);

Changing the prefix

commandHandler.setPrefix('?');
// '?' will be the new 

Others

Slash Commands

❓ This library is very very similar to the official Discord API so check it out :warning: ApplicationCommand = a created SlashCommand

Creating a Slash command

const slashCommand = new DiscordAdditions.SlashCommand(client, 'hello', 'Say hello'); // Return ApplicationCommand object
// client is your Discord.Client
// 'hello' is name of the command
// 'Say hello' is the description of the command

SlashCommandOption

const option = new DiscordAdditions.SlashCommandOption(6, 'user', 'Wich user you want the bot to say hello');

// Set if option is required
option.setRequired(true);

// Set a list of SlashCommandOptionChoice
option.setChoices([choice1, choice2, choice3...]);

// Set a list of SlashCommandOption (only for SUB_COMMAND and SUB_COMMAND_GROUP)
option.setOptions([option1, option2, option3...]);

// Adding the option to the slashCommand
slashCommand.setOptions([option]);

SlashCommandOptionType

SlashCommandOptionTypes.SUB_COMMAND; // Return 1
SlashCommandOptionTypes.SUB_COMMAND_GROUP; // Return 2
SlashCommandOptionTypes.STRING; // Return 3
SlashCommandOptionTypes.INTEGER; // Return 4
SlashCommandOptionTypes.BOOLEAN; // Return 5
SlashCommandOptionTypes.USER; // Return 6
SlashCommandOptionTypes.CHANNEL; // Return 7
SlashCommandOptionTypes.ROLE; // Return 8
SlashCommandOptionTypes.MENTIONABLE; // Return 9

SlashCommandOptionChoice

const choice = new DiscordAdditions.SlashCommandOptionChoice('Hello 1', 'hello_1');
// 'Hello 1' is the name of the choice
// 'hello_1' is the value of the choice

Application Commands

Get an ApplicationCommand

// From a SlashCommand
const applicationCommand = await slashCommand.create();

// From an ApplicationCommand Id
const applicationCommand = await DiscordAdditions.ApplicationCommand.getFromApplicationCommandId(client, '866621370782711838', '865949299509297192');
// client is your Discord.Client
// '866621370782711838' is the ApplicationCommand Id
// ''865949299509297192' is the Guild Id (optional, if the command is a GuildApplicationCommand)

Invites

Creating an InviteSketch

const inviteSketch = new DiscordAdditions.InviteSketch(client, channel, 0, 42, false, true);
// client is your Discord.Client
// channel is your GuildChannel (where you want the invite to be created)
// 0 (optional), is the maxAge (in seconds) 0 = Never. Value must be between 0 and 604800
// 42 (optional), is the maxUses. Value must be between 0 and 100;
// false (optional) whether this invite only grants temporary membership
// true (optional) if true, don't try to reuse a similar invite

Setting an activity

inviteSketch.setTargetApplicationId('755600276941176913'));
// '755600276941176913' the applicationId

// or you can use this enum : ActivitiesApplicationId

ActivitiesApplicationId

ActivitiesApplicationId.POKER_NIGHT; // Return '755827207812677713'
ActivitiesApplicationId.BETRAYAL_IO; // Return '773336526917861400'
ActivitiesApplicationId.YOUTUBE_TOGETHER; // Return '755600276941176913'
ActivitiesApplicationId.FISHINGTON_IO; // Return '814288819477020702'
ActivitiesApplicationId.CHESS_IN_THE_PARK; // Return '832012774040141894'

Creating an Invite

const invite = await inviteSketch.create();

// console.log(invite.code);

Dynamic Timestamps

Creating the timestamp

const dynamicTimestamp = new DiscordAdditions.DynamicTimestamp(new Date(), 'R');

Once you created the Dynamic Timestamp you can use it in any message with the toString() method

Changing the date

// From a date
dynamicTimestamp.setDate(new Date());

// From an unix timestamp
dynamicTimestamp.setTimestamp(1626613839);

Changing the display style

// With the letter
dynamicTimestamp.setDisplayStyle('R');

// With the provided enum
dynamicTimestamp.setDisplayStyle(DiscordAdditions.DynamicTimestamp.DynamicTimestampStyles.RELATIVE_TIME)

❓ See more on the official Discord Documentation

Use

// Return the timestamp as a string usable in a message
dynamicTimestamp.toString();

// Example
client.on('ready', () => {
  console.log('Bot online');
  client.channels.cache.get(logChannelId).send(`Bot online!\nMessage sended ${dynamicTimestamp.toString()}`);
});

Result : image

DynamicTimestampStyles

DynamicTimestampStyles.SHORT_TIME; // Return 't'
DynamicTimestampStyles.LONG_TIME; // Return 'T'
DynamicTimestampStyles.SHORT_DATE; // Return 'd'
DynamicTimestampStyles.LONG_DATE; // Return 'D'
DynamicTimestampStyles.SHORT_DATE_TIME; // Return 'f'
DynamicTimestampStyles.LONG_DATE_TIME; // Return 'F'
DynamicTimestampStyles.RELATIVE_TIME; // Return 'R'

If you see any error here feel free to open an issue

Todo

  • Add an EventHandler
  • Add an SlashCommandHandler
  • Add support for MessageComponents