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-role-manager

v1.2.5

Published

A simple discrod role manager, which will allow verified users to assign certain roles to other users.

Downloads

7

Readme

discord-role-manager

A simple discrod role manager, which will allow verified users to assign certain roles to other users. This script will help you to manage role in text role play discrod server or other servers, who need to have a role leader.

Installation

  npm i discord-role-manager --save

Usage

standard usage

const Discord = require('discord.js');
const client = new Discord.Client();
const { RoleManger } = require('discord-role-manager') // get npm;

const roleManger = new RoleManger(client, {
	storagePath: './roleStorage.json',
	localization: 'en' //Available localization is: ru; en. If you want to change localization or add your own language, go to the package dir and change localization.json
});
client.roleManger = roleManger;

client.on('message', message => {
	if (message.content.startsWith('!addRole')) client.roleManger.addRole(message).catch(errorMessage => {
		errorMessage.delete({ timeout: 1000 });
	}); //Add new role to ./roleStorage.json and catch eroor message
	else if (message.content.startsWith('!giveRoleToUser')) client.roleManger.giveRoleToUser(message).catch(errorMessage => {
		errorMessage.delete({ timeout: 1000 });
	}); //Give role to user and catch eroor message
	else if (message.content.startsWith('!removeRoleFromUser')) client.roleManger.removeRoleFromUser(message).catch(errorMessage => {
		errorMessage.delete({ timeout: 1000 });
	}); //remove role from user and catch eroor message
	else if (message.content.startsWith('!removeRole')) client.roleManger.removeRole(message).catch(errorMessage => {
		errorMessage.delete({ timeout: 1000 });
	}); //Remove role from ./roleStorage.json and catch eroor message
	else if (message.content.startsWith('!changeRoleAdmitUsers')) client.roleManger.changeRoleAdmitUsers(message).catch(errorMessage => {
		errorMessage.delete({ timeout: 1000 });
	}); //Change same role admit users.
	else if (message.content.startsWith('!getRoleInfo')) client.roleManger.getRoleInfo(message)
		.then(info => {
			console.log(info);
		}).catch(errorMessage => {
			errorMessage.delete({ timeout: 1000 });
		}); //Get and log role info.
	else if (message.content.startsWith('!getUserAdmitRoles')) client.roleManger.getUserAdmitRoles(message)
		.then(info => {
			console.log(info);
		}).catch(errorMessage => {
			errorMessage.delete({ timeout: 1000 });
		}); //Get and log roles where user have admit permissions.
});

client.login('YOUR_BOT_TOKEN_HERE');

if you want to use third-party databases

const Discord = require('discord.js');
const client = new Discord.Client();
const { RoleManger } = require('discord-role-manager') // get npm;
const rolesData = {
	"598155112153743418": {
		"630725911930732546": {
			"admitUsers": [ "150656108455788544" ]
		}
	}
} //Here you need to get data from the database, this obj just example

const roleManger = new RoleManger(client, {
	rolesData: rolesData,
	localization: 'en' //Available localization is: ru; en. If you want to change localization or add your own language, go to the package dir and change localization.json
});
client.roleManger = roleManger;

client.on('message', message => {
	if (message.content.startsWith('!addRole')) client.roleManger.addRole(message)
		.then(data => {
			if (!rolesData[message.guild.id]) rolesData[message.guild.id] = { };

			rolesData[message.guild.id][data.roleId] = { admitUsers: data.admitUsers };
			//Here you need to save data to the database, this obj just example
		})
		.catch(errorMessage => {
			errorMessage.delete({ timeout: 1000 });
		});
});

client.login('YOUR_BOT_TOKEN_HERE');

Discord usage

Creat new role, and set admit user.

Now this user can get this role to other users.

All Classes

index

  • RoleManger - RoleManger class

All functions

RoleManger

  • addRole(message) - Add new role to ./roleConfig.json. return new Promise(resolve(Object), reject(errorMessage))
  Discord message example:
  !addRole @role @user1 @user2 @user3....
  
  @user1 and others it's admit users (users, who can use removeRoleFromUser and giveRoleToUser for this current role)
  • removeRole(message) - Remove role from ./roleConfig.json. return new Promise(resolve(Object), reject(errorMessage))
  Discord message example:
  !removeRole @role
  • changeRoleAdmitUsers(message) - Change existing role admit users. return new Promise(resolve(Object), reject(errorMessage))
  Discord message example:
  !changeRoleAdmitUsers @role @user1 @user2 @user3....
  
  @user1 and others it's admit users (users, who can use removeRoleFromUser and giveRoleToUser for this current role)
  • getRoleInfo - Return info about role. return new Promise(resolve(Object), reject(errorMessage))
  Discord message example:
  !getRoleInfo @role
  • getUserAdmitRoles - Return info about all roles, where user have admit permissions. return new Promise(resolve(Array), reject(errorMessage))
  Discord message example:
  !getRoleInfo @user
  • giveRoleToUser - Give role to the user. return new Promise(resolve(string), reject(errorMessage))
  Discord message example:
  !giveRoleToUser @role @user
  
  available only for this role admit user
  • removeRoleFromUser - Remove role from user. return new Promise(resolve(string), reject(errorMessage))
  Discord message example:
  !removeRoleFromUser @role @user
  
  available only for this role admit user

RoleManger opts

  • storagePath = string - path to your storage.json file.
  • rolesData = Object - this opts need you, if you use third-party databases. Warning storagePath replaces this parameter.
  • localization = string - localization language (en by default). Available localization is: ru; en. If you want to change localization or add your own language, go to the package dir and change localization.json

Events

  • addedRoleToUser - Emitted whenever user give role to other user return(userWhoRemoveRole, userWhoLooseRole, role)
  • removedRoleFromUser - Emitted whenever user remove role from other user return(userWhoRemoveRole, userWhoLooseRole, role)

Recommendation

  • Make the verify to the addRole removeRole changeRoleAdmitUsers commands so that only administrators can use these commands