Skip to content

Commit

Permalink
fix(role_buttons): defer reply in case applying roles is slow
Browse files Browse the repository at this point in the history
  • Loading branch information
AtoraSuunva committed Nov 30, 2024
1 parent c255b0e commit e045cf2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utility/role_buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ const ROLE_BUTTON_ID = 'role-button'
async function handleInteractionCreate(interaction: Interaction) {
if (!interaction.isButton()) return

await interaction.deferReply({
ephemeral: true,
})

const [command, roleID, onlyOneStr] = interaction.customId.split(':')
const onlyOne = onlyOneStr === 'true'

Expand All @@ -207,9 +211,8 @@ async function handleInteractionCreate(interaction: Interaction) {
const role = guild.roles.cache.get(roleID)

if (!role) {
await interaction.reply({
await interaction.editReply({
content: "That role doesn't seem to exist, maybe it was deleted?",
ephemeral: true,
})
return
}
Expand Down Expand Up @@ -250,16 +253,14 @@ async function handleInteractionCreate(interaction: Interaction) {
if (!member.roles.cache.has(role.id)) {
memberRoles.push(role)
await member.roles.set(memberRoles)
await interaction.reply({
await interaction.editReply({
content: `You now have the ${role} role${addendum}.`,
ephemeral: true,
})
} else {
memberRoles.splice(memberRoles.indexOf(role), 1)
await member.roles.set(memberRoles)
await interaction.reply({
await interaction.editReply({
content: `You no longer have the ${role} role${addendum}.`,
ephemeral: true,
})
}
}

0 comments on commit e045cf2

Please sign in to comment.