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

discordjs-variables

v2.0.0

Published

create custom variables for your discord bot, allow users to customize their welcome messages

Downloads

13

Readme

introduction

discordjs-variables is a package that makes it super easy to create custom variables for your discord bot.

If you don't know what I am talking about view the images below for examples.

This package is built on top of discord.js so only use this if your bot is using the discord.js framework .

npm install discordjs-variables

install discord.js

npm install discord.js

How To use

Create a converter are rule file to store the converter object and the rules for your custom variables

import {Converter, Rules} from "discordjs-variables"

// create new variables here
const rules = new Rules([
  { 
    identifier: "{username}",  
    eventType: "message",
    definition: (e) => e.user.username;
  }
])

// initialize your converter then pass your variables down
const converter = new Converter(rules);

// export it
export default converter

Then, integrate it into your project how you use it is up to you

import { Client, GatewayIntentBits } from 'discord.js';
import converter from "./converter.js" // imports the converter

const client = new Client({ intents: [GatewayIntentBits.Guilds] });


client.on('messageCreate', async message => {
 message.reply(converter.parseOnMessage(message, "{username}, you just send a message "))  // JackWilder, you just send a message
});

client.login(TOKEN);

Rules class

The Rules class gives you the ability to create custom discord variables, The . Rules class takes an Array of objects as param, Each containing the following keys

| Key | Description | Type | |--|--| -- | | identifier | This is the variable name, The parser will search a string then replace the identifier with the return value of definition function | string | | eventType | The Discord Client event the variable is meant for. Note you can only use the parser associated with the event type to parse it | EventShortHand| | definition| Allows you to add meaning to the identifier, what ever the return value of this function is it will replace the identifier that is found in a string|(e: any) => string | number|

Converter Methods

The converter class contains methods with different ways to parse a string based on a discord.js client event. (Am working on a single parse method)

| Method| Description | Type| |--|--|--| | parseOnMessage() | Parse strings in the messageCreate event | (event: Message, text: string) => string | | parseOnMemberJoin() | Parse strings in the messageCreate event | (event: GuildMember, text: string) => string |