Add user option

This commit is contained in:
Ethan Lane 2024-07-04 18:56:05 +01:00
parent 690b63470a
commit 6f4ff1df06
2 changed files with 10 additions and 4 deletions

View file

@ -12,7 +12,11 @@ export default class Moons extends Command {
.addSubcommand(subcommand => .addSubcommand(subcommand =>
subcommand subcommand
.setName('list') .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) { public override async execute(interaction: CommandInteraction) {

View file

@ -3,17 +3,19 @@ import Moon from "../../../database/entities/Moon";
import EmbedColours from "../../../constants/EmbedColours"; import EmbedColours from "../../../constants/EmbedColours";
export default async function ListMoons(interaction: CommandInteraction) { 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) { 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; return;
} }
const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`); const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`);
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(`${interaction.user.username}'s Moons`) .setTitle(`${user.username}'s Moons`)
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setDescription(description.join("\n")) .setDescription(description.join("\n"))
.setFooter({ text: `${moons.length} moons` }); .setFooter({ text: `${moons.length} moons` });