Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added avatar,uptime,userinfo commands! #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions slashCommands/info/avatar.js
Original file line number Diff line number Diff line change
@@ -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] })
}
};
32 changes: 32 additions & 0 deletions slashCommands/info/uptime.js
Original file line number Diff line number Diff line change
@@ -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]})

}
};
114 changes: 114 additions & 0 deletions slashCommands/info/userinfo.js
Original file line number Diff line number Diff line change
@@ -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
}
);

},
};