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

reaction-role

v5.0.1

Published

ReactionRole is a module that allows you to create Discord reaction role easily!

Downloads

922

Readme

Discord ReactionRole client

totalDownloads weeklyDownloads version license GitHub stars

  • ReactionRole is a module that allows you to create Discord reaction role easily!
  • This module is compatible with all node.js discord wrappers (like discord.js, eris, discord.js-commando etc.)
  • You also don't need to write any bot code if you want! You can also use this module alone. You just need a Discord Bot Token!
  • Database support and TypeScript definitions are built-in!

IMPORTANT NOTE


You have to turn on "Server Members Intent" option to use this package properly. ReactionRoleWarningImage

Usage

Simple example:

const { ReactionRole, EType } = require("reaction-role");

const client = new ReactionRole({
	token: "YOUR_BOT_TOKEN",
});

async function bootstrap() {
	const option1 = client.createOption({
		clickable_id: "EMOJI_ID",
		roles: ["ROLE_ID"],
		type: EType.NORMAL,
	});

	const option2 = client.createOption({
		clickable_id: "EMOJI_ID",
		roles: ["ROLE_ID"],
		type: EType.ONCE,
	});

	await client.createMessage({
		channel_id: "CHANNEL_ID",
		clickables: [option1, option2],
		message_id: "MESSAGE_ID",
	});

	client.init();
}

bootstrap();

Creating new messages:

client.on("message", (message) => {
	if (message.content == "!create") {
		// you can take any user input and use it to create new option and message

		// create a simple option
		const option = client.createOption({
			clickable_id: "EMOJI_ID",
			roles: ["ROLE_ID"],
			type: EType.NORMAL,
		});

		await client.createMessage({
			channel_id: "CHANNEL_ID",
			clickables: [option],
			message_id: "MESSAGE_ID",
		});

		// and you are done! New message and options are added to system
	}
});

Execute Custom Code

You can execute your own code when a user clicks on a reaction. You can do this by using clickable type EType.CUSTOM.

const { ReactionRole, EType } = require("reaction-role");

const client = new ReactionRole({
	token: "YOUR_BOT_TOKEN",
});

async function bootstrap() {
	const option = client.createOption({
		clickable_id: "EMOJI_ID",
		roles: ["ROLE_ID"],

		// These lines are important! everything else is same as normal
		type: EType.CUSTOM,
		onClick: (clickable, member) => {
			console.log(
				member.user.username + " clicked on " + clickable.clickable_id,
			);
		},
		onRemove: (clickable, member) => {
			console.log(
				member.user.username + " removed " + clickable.clickable_id,
			);
		},
	});

	await client.createMessage({
		channel_id: "CHANNEL_ID",
		clickables: [option],
		message_id: "MESSAGE_ID",
	});

	client.init();
}

bootstrap();

Using Custom Databases

You can change get, save and delete events of system with <ReactionRole>.onGet(TOnGetFN), <ReactionRole>.onSet(TOnSetFN) and <ReactionRole>.onDelete(TOnDeleteFN) methods. Here is an example with quick.db:

const { ReactionRole, EType } = require("reaction-role");

const client = new ReactionRole({
	token: "YOUR_BOT_TOKEN",
});

// SETTING CUSTOM DATABASE START
// choose your favourite database module
const db = require("quick.db");

// update save events
client
	.onGet(async () => {
		const saved = (await db.get("reaction_roles")) || {};
		return saved;
	})
	.onSet(async (data) => {
		await db.set("reaction_roles", data);
	})
	.onDelete(async (message_id) => {
		await db.delete(`reaction_roles.${message_id}`);
	});
// SETTING CUSTOM DATABASE END

// ... use it as normal

Useful Links

  • Discord: https://338.rocks/discord
  • Github: https://github.com/barbarbar338/reaction-role/
  • NPM: https://www.npmjs.com/package/reaction-role

Contact Me For More Help

\ ゜ o ゜)ノ