Skip to content

Commit 5504df8

Browse files
committed
Edit original message
This edits the original archival warning message rather than adding a new one (thus restarting archival timer).
1 parent 8d528c5 commit 5504df8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

discord-scripts/thread-management/check-thread-archiving.ts

+19-3
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,26 @@ async function checkThreadStatus(
389389

390390
// We can then archive the thread if the expiry time has been reached or passed
391391
if (autoArchiveTime - currentTime <= 0) {
392+
const warningKey = `thread-warning:${threadId}`
393+
const warningMessageId = robot.brain.get(warningKey)
394+
395+
if (warningMessageId) {
396+
try {
397+
const warningMessage = await thread.messages.fetch(warningMessageId)
398+
// this will edit the original message to indicate the thread has been archived
399+
await warningMessage.edit({
400+
content:
401+
"This thread is now archived as the auto-archive duration has been reached.",
402+
components: [],
403+
})
404+
} catch (error) {
405+
robot.logger.error(
406+
`Failed to edit the warning message for thread ${threadId}: ${error}`,
407+
)
408+
}
409+
}
410+
392411
await thread.setArchived(true)
393-
await thread.send(
394-
"This thread is now archived as the auto-archive duration has been reached.",
395-
)
396412
robot.logger.info(
397413
`Archived thread ${threadId} as the auto-archive time has been reached.`,
398414
)

0 commit comments

Comments
 (0)