Untitled
unknown
javascript
14 days ago
2.7 kB
2
Indexable
Never
const {Client, IntentsBitField} = require("discord.js"); const {token} = require("../config.json"); const client = new Client({intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.GuildPresences, ]}); client.on('messageCreate', (message) => { if (message.author.bot) return; if (!message.content.toUpperCase().startsWith(";UPDATE")) return; const arg1 = message.content.split(" ")[1]; //const channel = message.guild.channels.cache.get(channel_id); const members = message.guild.members.cache; membersWithHeightRole = members.size; totalHeightsInInches = 0; reply = "|"; members.forEach(member => { const heightRole = member.roles.cache.filter((role) => /^\d/.test(role.name) && role.name.indexOf("'") > -1).first(); if (!heightRole) { membersWithHeightRole--; } else { if (heightRole.name.startsWith("3'11 -")) { totalHeightsInInches += 3 * 12 + 9.25; reply += ` ${member.user.username}: 3'9.25" |`; } else if (heightRole.name.startsWith("3'7")) { membersWithHeightRole--;//3 * 12 + 7; } else { console.log(member.user.username);console.log(heightRole.name); feet = Number(heightRole.name.split("'")[0]); console.log(feet); inches = Number(heightRole.name.split("'")[1]); console.log(inches); height = feet * 12 + inches; reply += ` ${member.user.username}: ${height}" |`; if (height == NaN) { membersWithHeightRole--; height = 0; } totalHeightsInInches += height; } } }); avgHeight = totalHeightsInInches / membersWithHeightRole; console.log(`average height: ${avgHeight} inches.`); avgHeightInches = avgHeight % 12; avgHeightFeet = (avgHeight - avgHeightInches) / 12; avgHeightDisplay = `${avgHeightFeet}'${avgHeightInches}"` if(arg1 === "1") message.reply(reply); message.reply(`Average height of members with a height role (${membersWithHeightRole}): ${avgHeightDisplay} (${avgHeight} inches)`); //channel.setName(newChannelName) //if(channel.name != newChannelName) message.reply("You can only change the name of a channel every 10 minutes (discord API rate limit)."); // var datetime = new Date(); // console.log(datetime.toISOString().slice(0,10)); }) client.login(token);
Leave a Comment