Add list moons command #449
2 changed files with 10 additions and 4 deletions
|
@ -12,7 +12,11 @@ export default class Moons extends Command {
|
|||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
.setName('list')
|
||||
.setDescription('List moons you have obtained'));
|
||||
.setDescription('List moons you have obtained')
|
||||
.addUserOption(option =>
|
||||
option
|
||||
.setName("user")
|
||||
.setDescription("The user to view (Defaults to yourself)")));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
|
|
|
@ -3,17 +3,19 @@ import Moon from "../../../database/entities/Moon";
|
|||
import EmbedColours from "../../../constants/EmbedColours";
|
||||
|
||||
export default async function ListMoons(interaction: CommandInteraction) {
|
||||
const moons = await Moon.FetchMoonsByUserId(interaction.user.id);
|
||||
const user = interaction.options.get("user")?.user ?? interaction.user;
|
||||
|
||||
const moons = await Moon.FetchMoonsByUserId(user.id);
|
||||
|
||||
if (!moons || moons.length == 0) {
|
||||
await interaction.reply("You do not have any moons.");
|
||||
await interaction.reply(`${user.username} does not have any moons.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`${interaction.user.username}'s Moons`)
|
||||
.setTitle(`${user.username}'s Moons`)
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setDescription(description.join("\n"))
|
||||
.setFooter({ text: `${moons.length} moons` });
|
||||
|
|
Loading…
Reference in a new issue