Skip to content

Commit d9d6c38

Browse files
committed
Use new components v2
1 parent 39a1b4d commit d9d6c38

File tree

1 file changed

+40
-43
lines changed

1 file changed

+40
-43
lines changed

src/commands/inventar.ts

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import {
2-
type APIEmbed,
2+
ActionRowBuilder,
3+
ButtonBuilder,
34
ButtonStyle,
45
type CommandInteraction,
56
ComponentType,
7+
ContainerBuilder,
8+
MessageFlags,
69
SlashCommandBuilder,
10+
TextDisplayBuilder,
711
type User,
812
} from "discord.js";
913

@@ -52,59 +56,52 @@ export default class InventarCommand implements ApplicationCommand {
5256
const firstItemIndex = pageIndex * pageSize;
5357
const pageContents = contents.slice(firstItemIndex, firstItemIndex + pageSize);
5458

55-
const embed = {
56-
title: `Inventar von ${user.displayName}`,
57-
fields: pageContents.map(item => {
58-
const rarityAttribute = lootDataService.extractRarityAttribute(item.attributes);
59-
const rarity =
60-
rarityAttribute &&
61-
rarityAttribute.attributeKindId !== LootAttributeKind.RARITY_NORMAL
62-
? ` (${rarityAttribute.displayName})`
63-
: "";
64-
65-
const shortAttributeList = item.attributes.map(a => a.shortDisplay).join("");
66-
67-
return {
68-
name: `${lootDataService.getEmote(context.guild, item)} ${item.displayName}${rarity} ${shortAttributeList}`.trim(),
69-
value: "",
70-
inline: false,
71-
};
72-
}),
73-
footer: {
74-
text: `Seite ${pageIndex + 1} von ${lastPageIndex + 1}`,
75-
},
76-
} satisfies APIEmbed;
59+
const list = pageContents.map(item => {
60+
const rarityAttribute = lootDataService.extractRarityAttribute(item.attributes);
61+
const rarity =
62+
rarityAttribute &&
63+
rarityAttribute.attributeKindId !== LootAttributeKind.RARITY_NORMAL
64+
? ` (${rarityAttribute.displayName})`
65+
: "";
66+
67+
const shortAttributeList = item.attributes.map(a => a.shortDisplay).join("");
68+
69+
return `${lootDataService.getEmote(context.guild, item)} ${item.displayName}${rarity} ${shortAttributeList}`.trim();
70+
});
71+
72+
const listItems = list.length > 0 ? list.map(l => `- ${l}`) : ["_leer_"];
7773

7874
return {
7975
components: [
80-
{
81-
type: ComponentType.ActionRow,
82-
components: [
83-
{
84-
type: ComponentType.Button,
85-
label: "<<",
86-
customId: "page-prev",
87-
disabled: pageIndex <= 0,
88-
style: ButtonStyle.Secondary,
89-
},
90-
{
91-
type: ComponentType.Button,
92-
label: ">>",
93-
customId: "page-next",
94-
disabled: pageIndex >= lastPageIndex,
95-
style: ButtonStyle.Secondary,
96-
},
97-
],
98-
},
76+
new ContainerBuilder()
77+
.addTextDisplayComponents(t => t.setContent(`## Inventar von ${user}`))
78+
.addTextDisplayComponents(
79+
...listItems.map(li => new TextDisplayBuilder().setContent(li)),
80+
)
81+
.addTextDisplayComponents(t =>
82+
t.setContent(`-# Seite ${pageIndex + 1} von ${lastPageIndex + 1}`),
83+
),
84+
new ActionRowBuilder<ButtonBuilder>().addComponents(
85+
new ButtonBuilder()
86+
.setCustomId("page-prev")
87+
.setLabel("<<")
88+
.setStyle(ButtonStyle.Secondary)
89+
.setDisabled(pageIndex <= 0),
90+
new ButtonBuilder()
91+
.setCustomId("page-next")
92+
.setLabel(">>")
93+
.setStyle(ButtonStyle.Secondary)
94+
.setDisabled(pageIndex >= lastPageIndex),
95+
),
9996
],
100-
embeds: [embed],
10197
} as const;
10298
}
10399

104100
let pageIndex = 0;
105101

106102
const callbackResponse = await interaction.reply({
107103
...buildMessageData(pageIndex),
104+
flags: MessageFlags.IsComponentsV2,
108105
withResponse: true,
109106
tts: false,
110107
});

0 commit comments

Comments
 (0)