Skip to content

Instantly share code, notes, and snippets.

@zinntikumugai
Last active June 14, 2019 09:03
Show Gist options
  • Save zinntikumugai/76e5fd51b12c5ef6937e9291f5bd5b8d to your computer and use it in GitHub Desktop.
Save zinntikumugai/76e5fd51b12c5ef6937e9291f5bd5b8d to your computer and use it in GitHub Desktop.
Discord.js get role user

Discord.js 役職取得

SensuのBOTを作ってる際の見つけたやつです

  1. メンションの役職(role)をすべて取得
  2. メッセージのサーバー(guild)に所属するユーザーのうち 1で手に入れた役職に所属する人を取得

sample

img

args,args_o当たりはいい感じに作り直せるので頑張ってみて(この書き方は結構汚いので) また、重複チェック等してないです

/*
requireとか .on('ready')とか
*/
client.on('message', message => {
if (message.author.id == client.user.id)
return;
var args = message.content.slice(configFile.Discord.prefix.length).trim().split(/ +/g);
let args_o = JSON.parse(JSON.stringify(args)); //JSの仕様上こうなる
var command = args.shift().toLocaleLowerCase();
console.log(args_o);
if(command !== "lrain") {
//normal
}else {
//lrain
//console.log(message.mentions.roles);
let roles = [];
message.mentions.roles.forEach(role => {
roles.push(role.id);
});
let members = [];
message.guild.members.forEach(member => {
member.roles.forEach(member_in_role => {
roles.forEach(role => {
if(member_in_role.id == role)
members.push(member.user.id);
})
});
});
console.log(members);
let list = "";
members.forEach(id => {
list += "<@" + id +">\n";
});
message.channel.send(
"<@" + message.author.id + "> \n"
+ "hit users\n"
+ list
)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment