Discord_API_Bot/slash-commands/info.js

60 lines
No EOL
2 KiB
JavaScript

const api = require("../helpers/api");
const { api_role_id, auth_url } = require("../config");
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("info")
.setDescription("Check your hosting info"),
async run(interaction) {
const deferOptions = { ephemeral: true };
await interaction.deferReply(deferOptions);
const footerText = { text: "Coded by @onurcansevinc" };
const authorText = { name: "Your Account's Information" };
const thumbnailOptions = { dynamic: true };
let infoEmbed = new EmbedBuilder()
.setTimestamp()
.setColor("Random")
.setFooter(footerText)
.setAuthor(authorText)
.setThumbnail(interaction.guild.iconURL(thumbnailOptions))
.setDescription(`You have not yet connected your Discord account to the hosting panel!\n Click [here](${auth_url}) to link your Discord account to the hosting panel!`);
const noLinkReply = { embeds: [infoEmbed] };
if (!interaction.member.roles.cache.has(api_role_id)) {
return interaction.editReply(noLinkReply);
}
let discordUser = await api.getDiscordUser(interaction.user.id);
const noDiscordUserReply = { embeds: [infoEmbed] };
if (!discordUser) {
return interaction.editReply(noDiscordUserReply);
}
let user = await api.getUser(discordUser.data[0].email);
const noUserReply = { embeds: [infoEmbed] };
if (!user) {
return interaction.editReply(noUserReply);
}
user = user.data[0];
let infoString = '';
infoString += `- **ID:** ${user.id}\n`;
infoString += `- **Balance:** $${user.balance}\n`;
infoString += `- **Status:** ${user.status === "active" ? "🟢 Active" : "🔴 Passive"}\n`;
infoString += `- **Created:** <t:${new Date(user.created_at) / 1000}:R>\n`;
infoString += `- **Last Login:** <t:${new Date(user.last_login_at) / 1000}:R>\n`;
infoEmbed.setDescription(infoString);
const userInfoReply = { embeds: [infoEmbed] };
return interaction.editReply(userInfoReply);
}
};