10 examples of 'discord.js check if user has role' in JavaScript

Every line of 'discord.js check if user has role' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
118export function isRole(args: NameType[], isCheckTrue?: boolean) {
119 return isInProperties(ROLES, args, isCheckTrue);
120}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

56export function isRole(args, isCheckTrue) {
57 return isInProperties(ROLES, args, isCheckTrue);
58}
32hasRole(role: string) : boolean {
33
34 if(this.roles && this.roles.length) {
35
36 let roles = this.roles;
37
38 if(role && roles && typeof roles === 'object' && roles.length) {
39 if(roles.indexOf(role) >= 0) {
40 return true;
41 }
42 }
43 }
44
45 return false;
46}
111async role(role, guild) {
112 if (role instanceof Role) return role;
113 if (typeof role === 'string' && this.constructor.regex.role.test(role)) return guild.roles.get(this.constructor.regex.role.exec(role)[1]);
114 return null;
115}
165function CheckRole(role, roles){
166 var found;
167 for (var i = 0; i < roles.length; i++) {
168 if(roles[i].name == role){
169 return true;
170 }
171 }
172 return found;
173}
11function hasRoleInChannel(channel, roles, nick) {
12 if (!channel || !roles) {
13 return false;
14 }
15
16 const channelID = channel.attr("data-id");
17 const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`);
18 const target = nick || network.attr("data-nick");
19 const user = channel.find(`.names .user[data-name="${escape(target)}"]`).first();
20 return user.parent().is("." + roles.join(", ."));
21}
32function isStaff(m, serverInfo) {
33 if (m.roles.has(serverInfo.roles.staff)) return true;
34 if (m.roles.has(serverInfo.roles.support)) return true;
35 if (m.roles.has(serverInfo.roles.moderator)) return true;
36 if (m.roles.has(serverInfo.roles.admin)) return true;
37 return false;
38}
678function userHasRole(role) {
679 var roles = (',' + window.NOW.user.roles + ','),
680 is_admin = roles.indexOf(',admin,') > -1;
681 if (role) {
682 return is_admin || roles.indexOf(',' + role + ',') > -1;
683 }
684 return is_admin;
685}
34export function hasRole(rolesRequired, rolesUser) {
35 let isAuthorized = false;
36 rolesRequired.forEach(rolReq => {
37 if (rolesUser.includes(rolReq))
38 isAuthorized = true;
39 return;
40 });
41 return isAuthorized;
42}
1function FindRole(role) {
2 for(i = 0; i < Server.Roles.length; i++) {
3 if(role == Server.Roles[i].Name) {
4 return true;
5 }
6 }
7 return false;
8}

Related snippets