My Bot isn't Deleting Archived Threads

When a Thread is closed or archived, it cannot delete the thread. It only deletes unclosed or active threads but I'd like it to delete threads regardless of if they are open, archived or closed within an hour.

Any Idea whats wrong here? using Python and latest version of JS

@tasks.loop(seconds=7.5)
async def check_and_delete_threads():
    try:
        # Replace CHANNEL_ID with the actual ID of the channel you want to check for threads in
        channel_id = 
        channel = bot.get_channel(channel_id)

        # Replace EXCLUDED_THREAD_ID with the ID of the thread you want to exclude from deletion
        excluded_thread_id = 

        if channel:
            for thread in channel.threads:
                if thread.id == excluded_thread_id:
                    continue

                # Check if the thread is older than 2 hours
                if time.time() - thread.created_at.timestamp() >= 7200 or thread.archived:
                    await thread.delete()
                    print(f"Thread {thread.name} deleted.")
                    # Remove thread info from the dictionary
                    thread_info.pop(str(thread.id), None)
Was this page helpful?