Browse Source

Add feature for checking scores

pull/41/head
Abheek Dhawan 3 years ago
parent
commit
1ea5c016b4
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 40
      src/commands/score.ts

40
src/commands/score.ts

@ -0,0 +1,40 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { MessageEmbed } from 'discord.js';
import log from '../helpers/log';
import userScore from '../models/userScore';
export const data = new SlashCommandBuilder()
.setName('score')
.setDescription('Returns the score of the current user or another')
.addUserOption(option => {
option
.setName('user')
.setDescription('The user to find the score for')
.setRequired(false);
return option;
});
export async function execute(interaction) {
const scoreEmbed = new MessageEmbed()
.setColor('#ffffff');
const user = interaction.options.getUser('user') || interaction.user;
userScore.findOne({ authorID: user.id }, async (err, score) => {
if (err) {
log({ logger: 'db', content: `Unable to obtain user: ${err}`, level: 'info' });
}
if (!score) {
await interaction.reply({ content: 'Unfortunately, that user does not seem to have used AwesomeSciBo yet.', ephemeral: true });
return;
}
scoreEmbed
.setAuthor({ name: user.tag, iconURL: user.displayAvatarURL(true) })
.setDescription(`Score: \`${score.score}\``);
await interaction.reply({ embeds: [scoreEmbed] });
});
}
Loading…
Cancel
Save