@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)
@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)