From 46984a76b2d2e646433cf4dcda9ae2c192be6a96 Mon Sep 17 00:00:00 2001 From: Tech Mattrix Date: Sat, 8 Oct 2022 15:31:43 +0530 Subject: [PATCH] Added avatar,uptime,userinfo commands! --- slashCommands/info/avatar.js | 46 +++++++++++++ slashCommands/info/uptime.js | 32 +++++++++ slashCommands/info/userinfo.js | 114 +++++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 slashCommands/info/avatar.js create mode 100644 slashCommands/info/uptime.js create mode 100644 slashCommands/info/userinfo.js diff --git a/slashCommands/info/avatar.js b/slashCommands/info/avatar.js new file mode 100644 index 00000000..ee13f04c --- /dev/null +++ b/slashCommands/info/avatar.js @@ -0,0 +1,46 @@ +const { ApplicationCommandType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ApplicationCommandOptionType } = require('discord.js'); + +module.exports = { + name: 'avatar', + description: "Display user's avatar", + type: ApplicationCommandType.ChatInput, + cooldown: 3000, + options: [ + { + name: 'user', + description: 'The avatar of the user you want to display.', + type: ApplicationCommandOptionType.User + } + ], + run: async (client, interaction) => { + const user = interaction.options.get('user')?.user || interaction.user; + + const embed = new EmbedBuilder() + .setTitle(`${user.tag}'s avatar`) + .setImage(user.displayAvatarURL({ size: 4096 })) + .setColor('Black') + .setFooter({ text: interaction.guild.name, iconURL: interaction.guild.iconURL() }) + .setTimestamp(); + + + const formats = ['png', 'jpg', 'jpeg', 'gif']; + const components = []; + formats.forEach(format => { + let imageOptions = { extension: format, forceStatic: format == 'gif' ? false : true }; + + if (user.avatar == null && format !== 'png') return; + if (!user.avatar.startsWith('a_') && format === 'gif') return; + components.push( + new ButtonBuilder() + .setLabel(format.toUpperCase()) + .setStyle('Link') + .setURL(user.displayAvatarURL(imageOptions)) + ) + }) + + const row = new ActionRowBuilder() + .addComponents(components); + + return interaction.reply({ embeds: [embed], components: [row] }) + } +}; \ No newline at end of file diff --git a/slashCommands/info/uptime.js b/slashCommands/info/uptime.js new file mode 100644 index 00000000..84edce7e --- /dev/null +++ b/slashCommands/info/uptime.js @@ -0,0 +1,32 @@ +const { ApplicationCommandType, EmbedBuilder } = require('discord.js'); + + +module.exports = { + name: 'uptime', + description: "Check the bot's latest uptime", + type: ApplicationCommandType.ChatInput, + cooldown: 3000, + run: async (client, interaction) => { + let totalSeconds = (client.uptime / 1000); + let hours = Math.floor(totalSeconds / 3600); + let days = Math.floor(totalSeconds / 86400); + totalSeconds %= 3600; +let minutes = Math.floor(totalSeconds / 60); +let seconds = Math.floor(totalSeconds % 60); + // let uptime = `**${hours}** hours, **${minutes}** minutes and **${seconds}** seconds`; +let embed = new EmbedBuilder() + .setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL({ dynamic: true }) }) + .setTitle('Botname Uptime') + .setThumbnail(client.user.displayAvatarURL()) + .setDescription(`**Uptime**: \` ${days} Day(s), ${hours} Hour(s), ${minutes} Minute(s), ${seconds} Second(s) \``) + //.setDescription(`${uptime}`) + .setColor("Black") + .setFooter({text: "Requested by "+ interaction.user.tag}) + .setTimestamp() + .setFooter({ text: interaction.guild.name, iconURL: interaction.guild.iconURL() }); + + + return interaction.reply({ embeds: [embed]}) + + } +}; diff --git a/slashCommands/info/userinfo.js b/slashCommands/info/userinfo.js new file mode 100644 index 00000000..d8f18616 --- /dev/null +++ b/slashCommands/info/userinfo.js @@ -0,0 +1,114 @@ +const { EmbedBuilder, PermissionsBitField } = require('discord.js'); +const moment = require('moment'); + +module.exports = { + name: "User Info", + type: 2, + run: async (client, interaction, config, db) => { + + const user = interaction.guild.members.cache.get(interaction.targetId); + + // Joined server/discord handler: + const joinedAgoCalculator = { + fetch: { + user(userInput, type) { + if (!userInput) throw new ReferenceError('You didn\'t provided the user to calculate.'); + + if (type === "discord") { + const joinedDiscordTimestampInNumber = new Date().getTime() - userInput.createdTimestamp; + const joinedDiscordTimestampInString = moment(userInput.user.createdAt).fromNow(); + + return joinedDiscordTimestampInString.toString(); // Just making sure it's string. + } else if (type === "server") { + const joinedServerTimestampInNumber = new Date().getTime() - userInput.joinedTimestamp; + const joinedServerTimestampInString = moment(userInput.joinedAt).fromNow(); + + return joinedServerTimestampInString.toString(); // Just making sure it's string. + } else throw new ReferenceError('Invalid type. Use "discord" or "server" only.'); + } + } + }; + + // Bot type handler: + const bot = { + true: "Yes", + false: "No" + }; + + // Acknowledgements handler: + const acknowledgements = { + fetch: { + user(userInput) { + let result; + + try { + if (userInput.permissions.has(PermissionsBitField.ViewChannel)) result = "Server Member"; + if (userInput.permissions.has(PermissionsBitField.KickMembers)) result = "Server Moderator"; + if (userInput.permissions.has(PermissionsBitField.ManageServer)) result = "Server Manager"; + if (userInput.permissions.has(PermissionsBitField.Administrator)) result = "Server Administrator"; + if (userInput.id === interaction.guild.ownerId) result = "Server Owner"; + + } catch (e) { + result = "Server Member"; + }; + + return result; + } + } + }; + + // Finals: + return interaction.reply( + { + embeds: [ + new EmbedBuilder() + .setTitle(`${user.user.tag}'s information:`) + .setThumbnail(user.displayAvatarURL( + { + dynamic: true + } + )) + .addFields( + { + name: "Full name", + value: `${user.user.tag}`, + inline: true + }, + { + name: "Identification", + value: `\`${user.id}\``, + inline: true + }, + { + name: `Roles [${user.roles.cache.size - 1}]`, // Use "-1" because we removed the "@everyone" role + value: `${user.roles.cache.map((ROLE) => ROLE).join(' ').replace('@everyone', '') || "[No Roles]"}`, + inline: true + }, + { + name: "Joined server at", + value: `${new Date(user.joinedTimestamp).toLocaleString()}\n(${joinedAgoCalculator.fetch.user(user, "server")})`, + inline: true + }, + { + name: "Joined Discord at", + value: `${new Date(user.user.createdTimestamp).toLocaleString()}\n(${joinedAgoCalculator.fetch.user(user, "discord")})`, + inline: true + }, + { + name: "A Bot?", + value: `${bot[user.user.bot]}`, + inline: true + }, + { + name: "Acknowledgements", + value: `${acknowledgements.fetch.user(user)}` + } + ) + .setColor('Blue') + ], + ephemeral: true + } + ); + + }, +}; \ No newline at end of file