(interaction, options)
| 140 | } |
| 141 | |
| 142 | static async safeEditReply(interaction, options) { |
| 143 | try { |
| 144 | const coordinator = this.getCoordinator(interaction); |
| 145 | if (coordinator?.isUsageFinalized()) { |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | if (!this.isInteractionValid(interaction)) { |
| 150 | logger.warn(`Interaction ${interaction.id} has expired before edit, ignoring`); |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (coordinator && (interaction._isPrefixCommand || coordinator.getReplyMessage())) { |
| 155 | await coordinator.edit(sanitizeEditReplyOptions(options)); |
| 156 | return true; |
| 157 | } |
| 158 | |
| 159 | if (!interaction.replied && !interaction.deferred) { |
| 160 | logger.debug(`Interaction ${interaction.id} not deferred, using reply fallback instead of edit`); |
| 161 | return await this.safeReply(interaction, options); |
| 162 | } |
| 163 | |
| 164 | await interaction.editReply(sanitizeEditReplyOptions(options)); |
| 165 | return true; |
| 166 | } catch (error) { |
| 167 | if (isInteractionUnavailableError(error)) { |
| 168 | logger.warn(`Interaction ${interaction.id} unavailable during edit:`, error.message); |
| 169 | return false; |
| 170 | } |
| 171 | if (error.code === 40060) { |
| 172 | logger.warn(`Interaction ${interaction.id} already acknowledged during edit:`, error.message); |
| 173 | return false; |
| 174 | } |
| 175 | if (error.name === 'InteractionNotReplied' || error.message.includes('not been sent or deferred')) { |
| 176 | logger.debug(`Interaction ${interaction.id} not replied, using reply fallback instead of edit:`, error.message); |
| 177 | return await this.safeReply(interaction, options); |
| 178 | } |
| 179 | if (error.code === 10008) { |
| 180 | logger.debug(`Interaction ${interaction.id} reply message deleted, using followUp fallback`); |
| 181 | try { |
| 182 | await interaction.followUp(options); |
| 183 | return true; |
| 184 | } catch (followUpError) { |
| 185 | if (isInteractionUnavailableError(followUpError)) { |
| 186 | logger.warn(`Interaction ${interaction.id} unavailable during followUp:`, followUpError.message); |
| 187 | return false; |
| 188 | } |
| 189 | logger.error('Failed to follow up after deleted reply:', followUpError); |
| 190 | return false; |
| 191 | } |
| 192 | } |
| 193 | logger.error('Failed to edit reply:', error); |
| 194 | return false; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static async safeReply(interaction, options) { |
| 199 | try { |
no test coverage detected