From bb55b555043d047677a7df4c88041d1842d2d8bb Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Fri, 2 Apr 2021 22:28:33 -0500 Subject: [PATCH] Add primitive userInfo command --- index.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/index.js b/index.js index a42b000..710713e 100644 --- a/index.js +++ b/index.js @@ -108,9 +108,46 @@ client.on("message", async message => { kick(message); } else if (message.content.toLowerCase().startsWith(`${prefix}addrole`)) { addRole(message); + } else if (message.content.toLowerCase().startsWith(`${prefix}userinfo`)) { + userInfo(message); } }); +async function userInfo(message) { + if (!message.content.split(" ")[1]) { + message.reply("query must contain at least 3 characters!") + return; + } + + if (message.content.split(" ")[1].length < 3) { + message.reply("query must contain at least 3 characters!") + return; + } + + const members = message.guild.members.cache.filter(member => { + if (member.nickname) { + return member.user.username.toLowerCase().includes(message.content.split(" ")[1].toLowerCase()) || member.nickname.toLowerCase().includes(message.content.split(" ")[1].toLowerCase()); + } else { + return member.user.username.toLowerCase().includes(message.content.split(" ")[1].toLowerCase()) + } + }); + + if (members.array().length < 1) { + message.reply("no members found with that name!"); + return; + } + + const member = members.array()[0]; + + const userInfoEmbed = new Discord.MessageEmbed() + .setAuthor(member.user.tag, member.user.avatarURL()) + .addField("Roles", member.roles.map(r => `${r}`).join(' • ')) + .setColor("00c5ff") + .setFooter("User ID: ", member.user.id) + .setTimestamp(); + message.channel.send(userInfoEmbed); +} + async function addRole(message) { if (!message.member.hasPermission('ADMINISTRATOR')) { message.reply("you do not have adequate permissions!")