🎨 profile commands

This commit is contained in:
Axel Olausson Holtenäs 2022-04-10 01:21:13 +02:00
parent a577fb35bf
commit 1e7d015f6a
No known key found for this signature in database
GPG key ID: 9347A5E873995701
3 changed files with 73 additions and 73 deletions

View file

@ -1,69 +0,0 @@
import i18next from 'i18next';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import users from '../../../helpers/database/models/userSchema';
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
try {
// Destructure member
const { member } = await interaction;
// Get options
const target = await interaction.options.getUser('target');
// Get discord user object
const discordUser = await interaction.client.users.fetch(
`${target ? target.id : interaction?.user?.id}`
);
// Get user object
const userDB = await users.findOne({
userId: await discordUser?.id,
guildId: interaction?.guild?.id,
});
// Create embed object
const embed = {
author: {
name: `${await discordUser.username}#${await discordUser.discriminator}`,
icon_url: await discordUser.displayAvatarURL(),
},
color: config.colors.success as any,
fields: [
{
name: `:dollar: Credits`,
value: `${userDB.credits || 'Not found'}`,
inline: true,
},
{
name: `:squeeze_bottle: Level`,
value: `${userDB.level || 'Not found'}`,
inline: true,
},
{
name: `:squeeze_bottle: Points`,
value: `${userDB.points || 'Not found'}`,
inline: true,
},
{
name: `:loudspeaker: Reputation`,
value: `${userDB.reputation || 'Not found'}`,
inline: true,
},
{
name: `:rainbow_flag: Language`,
value: `${userDB.language || 'Not found'}`,
inline: true,
},
],
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return await interaction.editReply({ embeds: [embed] });
} catch (e) {
// Send debug message
await logger.error(e);
}
};

View file

@ -1,10 +1,15 @@
// Dependencies
import { SlashCommandBuilder } from '@discordjs/builders'; import { SlashCommandBuilder } from '@discordjs/builders';
import view from './addons/view';
import { CommandInteraction } from 'discord.js'; import { CommandInteraction } from 'discord.js';
// Modules
import view from './modules/view';
// Function
export default { export default {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
.setName('profile') .setName('profile')
.setDescription('Your profile.') .setDescription('Check a profile.')
.addSubcommand((subcommand) => .addSubcommand((subcommand) =>
subcommand subcommand
.setName('view') .setName('view')
@ -16,9 +21,9 @@ export default {
) )
), ),
async execute(interaction: CommandInteraction) { async execute(interaction: CommandInteraction) {
// If subcommand is view // Module - View
if (interaction.options.getSubcommand() === 'view') { if (interaction.options.getSubcommand() === 'view') {
// Execute view addon // Execute Module - View
await view(interaction); await view(interaction);
} }
}, },

View file

@ -0,0 +1,64 @@
import i18next from 'i18next';
import config from '../../../../config.json';
import logger from '../../../handlers/logger';
import users from '../../../helpers/database/models/userSchema';
import { CommandInteraction } from 'discord.js';
export default async (interaction: CommandInteraction) => {
// Destructure
const { client, options, user, guild } = interaction;
// Target information
const target = options?.getUser('target');
// Discord User Information
const discordUser = await client.users.fetch(
`${target ? target?.id : user?.id}`
);
// User Information
const userObj = await users.findOne({
userId: discordUser?.id,
guildId: guild?.id,
});
// Embed object
const embed = {
author: {
name: `${discordUser.username}#${discordUser.discriminator}`,
icon_url: discordUser.displayAvatarURL(),
},
color: config.colors.success as any,
fields: [
{
name: `:dollar: Credits`,
value: `${userObj.credits || 'Not found'}`,
inline: true,
},
{
name: `:squeeze_bottle: Level`,
value: `${userObj.level || 'Not found'}`,
inline: true,
},
{
name: `:squeeze_bottle: Points`,
value: `${userObj.points || 'Not found'}`,
inline: true,
},
{
name: `:loudspeaker: Reputation`,
value: `${userObj.reputation || 'Not found'}`,
inline: true,
},
{
name: `:rainbow_flag: Language`,
value: `${userObj.language || 'Not found'}`,
inline: true,
},
],
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
// Send interaction reply
return await interaction.editReply({ embeds: [embed] });
};