diff --git a/util/parseMention.js b/util/parseMention.js new file mode 100644 index 0000000..ffc4f31 --- /dev/null +++ b/util/parseMention.js @@ -0,0 +1,36 @@ +module.exports = function (text, guild) { + var id = ""; + var ismention = false; + if ( + text.substring(0, 2) == "<@" && + text.substring(text.length - 1, text.length) == ">" + ) { + var start = 2; + if (text.substring(0, 3) == "<@!") start = 3; + id = text.substring(start, text.length - 1); + ismention = true; + } else { + if (!isNaN(text)) { + id = text; + } + } + if (!ismention) { + guild.members.cache.each(function (guildMember, guildMemberID) { + var compare = text.toLowerCase(); + if (guildMember.user.username.toLowerCase().includes(compare)) { + id = guildMemberID; + return; + } + if (guildMember.nickname) { + if (guildMember.nickname.toLowerCase().includes(compare)) { + id = guildMemberID; + return; + } + } + }); + } + return { id: id }; + +} + +