-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toggle role of user. #70
Comments
This is possible, but the bot doesn't do it yet. |
I created a command, but until now, it only adds the role to myself. Need to do some more stuff to make it work as its expected from @TheRealKev1n. |
its not even good code, but here it is: exports.toggleRole = {
usage: "<role (name or id)>",
description: "toggles a role of a user.",
process: function(bot,msg,suffix) {
var role_by_name = msg.channel.guild.roles.cache.find(role => role.name === suffix);
var role_by_id = msg.channel.guild.roles.cache.find(role => role.id === suffix);
if(role_by_name){
if(msg.member.roles.cache.find(role => role.name === suffix)){
msg.member.roles.remove(role_by_name);
msg.channel.send("Removed your role.");
}
else{
msg.member.roles.add(role_by_name);
msg.channel.send("Added the role to you.");
}
} else if(role_by_id){
if(msg.member.roles.cache.find(role => role.id === suffix)){
msg.member.roles.remove(role_by_id);
msg.channel.send("Removed your role.");
}
else{
msg.member.roles.add(role_by_id);
msg.channel.send("Added the role to you.");
}
} else {
msg.channel.send("role doesn't exist");
}
}
} |
I would suggest instead of looking directly at role id or name, look for a role mention in the command args and a user mention. from there it should check to see if the mentioned user has the mentioned role, if so then remove else add. EDIT 2:
I can try to find a sample code from my old repo, it might not work though because of the discord.js change. EDIT 1: exports.perm = {
usage: "set <can be @user or @role> or rm <can be @user or @role>",
description: "Used to set(add) or remove permissions from a @user or @role",
process: function(bot,msg,arg){
var args = arg.split(" ");
var permsFile = require("../../permissions.json");
var user, role;
if(args[0] == "set"){
if(typeof args[1] != 'undefined' && typeof args[2] != 'undefined' && typeof args[3] != 'undefined'){
var node1 = args[2];
var perm1;
if(args[3] == "true"){ perm1 = true; }else{ perm1 = false; }
try{
if(msg.mentions.users.first()){ console.log('User mention'); user = msg.mentions.users.first().id; }
if(msg.mentions.roles.first()){ console.log('Role mention '+msg.mentions.roles.first().id); role = msg.mentions.roles.first().id; }
}catch(err){ console.log('Error occured at: '+err+' Mentions.first() is undefined'); }
if(typeof user != 'undefined'){
if(typeof permsFile.users[user] == 'undefined'){ permsFile.users[user] = {[node1]:perm1}; }
else{ permsFile.users[user][node1] = perm1; }
}else if(typeof role != 'undefined'){
if(typeof permsFile.roles[role] == 'undefined'){ permsFile.roles[role] = {[node1]:perm1}; }
else{ permsFile.roles[role][node1] = perm1; }
}
}else{ msg.channel.send('__Parameters can\'t be left blank: '+typeof args[1]+', '+typeof args[2]+', '+typeof args[3]+'__'); }
}else if(args[0] == "rm"){
if(typeof args[1] != 'undefined' && typeof args[2] != 'undefined'){
var node1 = args[2];
try{
if(msg.mentions.users.first()){ user = msg.mentions.users.first().id; }
if(msg.mentions.roles.first()){ role = msg.mentions.roles.first().id; }
}catch(err){ console.log('Error occured at: '+err+' Mentions.first() is undefined'); }
if(typeof user != 'undefined'){ delete permsFile.users[user][node1]; }
else if(typeof role != 'undefined'){ delete permsFile.roles[role][node1]; }
}else{ msg.channel.send('__Parameters can\'t be left blank: '+typeof args[1]+', '+typeof args[2]+', '+typeof args[3]+'__'); }
}else{ msg.channel.send("__Too few Arguments: either add or rm.__"); }
try{
if(fs.lstatSync("./permissions.json").isFile()){ console.log("WARNING: permissions.json found but we couldn't read it!\n" + e.stack); }
} catch(e2){
if (!fs.writeFile("./permissions.json",JSON.stringify(permsFile,null,2))){
//console.log('Write success!');
}}
} |
Here is a perm based toggle of a mentioned user and role exports.perm = {
usage: "<@user> <@role>",
description: "Used to toggle @role of specified @user",
process: function(bot,msg,arg){
var args = arg.split(" ");
var user, role;
if(typeof args[0] != 'undefined' && typeof args[1] != 'undefined'){
try{
if(msg.mentions.members.first()){ console.log('User mention '+msg.mentions.members.first().id); user = msg.mentions.members.first(); }
if(msg.mentions.roles.first()){ console.log('Role mention '+msg.mentions.roles.first().id); roleid = msg.mentions.roles.first().id; }
}catch(err){ console.log('Error occured at: '+err+' Mentions.first() is undefined'); }
if(user.roles.cache.find(role => role.id === roleid)){
user.roles.remove(roleid);
msg.channel.send("Removed the role from <@!"+user+">.");
}
else{
user.roles.add(roleid);
msg.channel.send("Added the role to <@!"+user+">.");
}
} else{ msg.channel.send('__Parameters can\'t be left blank: '+typeof args[0]+', '+typeof args[1]+'__'); }else{ msg.channel.send("__Too few Arguments.__"); }
}
} |
On branch role-perm Changes to be committed: modified: plugins/Admin/admin.js
Hello,
I got 2 groups member and vip
is it possible that the bot adds vip to a user with a command? and remove it with a command
Regards,
Kevin
The text was updated successfully, but these errors were encountered: