undefined
undefined
DIAdiscord.js - Imagine an app
Created by undefined on 6/13/2024 in #djs-questions
Collector not updating message embed
No errors in console or anything,
/** @type string */
let list = intr.options.getString("name", true)
let page = 1
let levelsppage = intr.options.getInteger("levels-per-page", false) ?? 5
let embed = await createEmbedForList(list, levelsppage, page)
let response = await intr.reply(embed)

let collector = response.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 120_000
})

collector.on("collect", async collectorIntr => {
console.log("collection moment")
if (collectorIntr.user.id !== intr.user.id) {
// wrong person!
await collectorIntr.reply({
content: "This is not your list! Use /list to create your own.",
ephemeral: true
})
return
}

switch(collectorIntr.customId) {
case "page-prev":
await collectorIntr.update(createEmbedForList(list, levelsppage, --page))
break
case "page-next":
await collectorIntr.update(createEmbedForList(list, levelsppage, ++page))
break
default:
// uh oh
console.warn("uh oh %s", collectorIntr.customId)
}
})

collector.on("end", async () => {
console.log("timeout")
let embed = await createEmbedForList(list, levelsppage, page)
embed.components[0].components[0].setDisabled(true)
embed.components[0].components[1].setDisabled(true)
intr.editReply(embed)
})
/** @type string */
let list = intr.options.getString("name", true)
let page = 1
let levelsppage = intr.options.getInteger("levels-per-page", false) ?? 5
let embed = await createEmbedForList(list, levelsppage, page)
let response = await intr.reply(embed)

let collector = response.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 120_000
})

collector.on("collect", async collectorIntr => {
console.log("collection moment")
if (collectorIntr.user.id !== intr.user.id) {
// wrong person!
await collectorIntr.reply({
content: "This is not your list! Use /list to create your own.",
ephemeral: true
})
return
}

switch(collectorIntr.customId) {
case "page-prev":
await collectorIntr.update(createEmbedForList(list, levelsppage, --page))
break
case "page-next":
await collectorIntr.update(createEmbedForList(list, levelsppage, ++page))
break
default:
// uh oh
console.warn("uh oh %s", collectorIntr.customId)
}
})

collector.on("end", async () => {
console.log("timeout")
let embed = await createEmbedForList(list, levelsppage, page)
embed.components[0].components[0].setDisabled(true)
embed.components[0].components[1].setDisabled(true)
intr.editReply(embed)
})
createEmbedForList returns an object containing
{
embeds: [ Embed ],
components: [ ActionRow ]
}
{
embeds: [ Embed ],
components: [ ActionRow ]
}
12 replies