Skip to content

Commit

Permalink
dismiss role select embed after 10s of inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiviexd committed Jan 22, 2025
1 parent 4f9085c commit 6a21e5d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions modules/selectroles/handleSelectRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export async function handleSelectRoles(button: ButtonInteraction) {
.setDescription(
`Hey <@${button.user.id}>, Select the roles you want to add or remove from yourself.`
)
.setColor(colors.pink);
.setColor(colors.pink)
.setFooter({ text: "This message will be dismissed after 10 seconds of inactivity" });

const response = await button.followUp({
embeds: [currentRolesMenuEmbed],
Expand All @@ -72,16 +73,25 @@ export async function handleSelectRoles(button: ButtonInteraction) {
],
});

const messageTimeout = setTimeout(async () => {
try {
await response.delete();
} catch (error) {
console.error("Failed to delete roles menu:", error);
}
}, 10000); // 10 seconds

const collector = new InteractionCollector(button.client, {
filter: (i) =>
i.user.id == button.user.id && i.customId == idFields[0],
time: 300000,
});

collector.on("collect", async (menu: StringSelectMenuInteraction) => {
if (!selectRolesMessageData) return;

await menu.deferUpdate();
clearTimeout(messageTimeout);

if (!selectRolesMessageData) return;

const rolesToAdd = menu.values;
const rolesToRemove = selectRolesMessageData.roles.filter(
Expand Down

0 comments on commit 6a21e5d

Please sign in to comment.