MCPcopy
hub / github.com/codebymitch/TitanBot / safeEditReply

Method safeEditReply

src/utils/interactionHelper.js:142–196  ·  view source on GitHub ↗
(interaction, options)

Source from the content-addressed store, hash-verified

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 {

Callers 15

universalReplyMethod · 0.95
executeFunction · 0.80
executeFunction · 0.80
handleSetupSubcommandFunction · 0.80
handleConfigSubcommandFunction · 0.80
executeFunction · 0.80
executeFunction · 0.80
executeFunction · 0.80
executeFunction · 0.80
executeFunction · 0.80
handleReviewFunction · 0.80
handleListFunction · 0.80

Calls 9

getCoordinatorMethod · 0.95
isInteractionValidMethod · 0.95
safeReplyMethod · 0.95
sanitizeEditReplyOptionsFunction · 0.85
isUsageFinalizedMethod · 0.80
getReplyMessageMethod · 0.80
editMethod · 0.80
followUpMethod · 0.80

Tested by

no test coverage detected