Skip to content

Daily

Clear out old messages every night

Busy channels like bot logs stay short, with messages older than a week removed.

Runs
Daily
Apps
Discord
AI
Not needed
Access
Read Message History, Manage Messages

Send this to your assistant

Create a ClickRuntime automation: every night at 9pm, delete messages older than 7 days in #bot-logs on my Discord.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A server with a high-traffic support or bot-output channel fills with messages that stop being useful within days: old command results, stale announcements, temporary chat. Scrolling gets slower, new members stumble on outdated instructions, and screenshots of personal details stay around for months. Deleting messages by hand is tedious, and Discord's own tools only offer bulk deletion for recent messages.

Each night the automation lists the channels you named, pages through their messages and deletes any older than the number of days you set, such as seven. It pauses between deletions to respect Discord's rate limits, so a large backlog is cleared gradually without errors. By morning the channel holds only recent, relevant messages, and nobody had to stay up for it.

Servers with bot logs, trade channels or support queues find it most useful.

What you get out of it

  • Channels that stay short and readable

    A week of history is enough for most conversations. Newcomers see current messages instead of a wall of stale ones, and scrolling back to find something stays quick instead of becoming slower with every month that passes.

  • Old personal details do not linger

    Messages containing emails, usernames or screenshots disappear on schedule. That reduces what could be exposed if the server is ever compromised, and it fits with a sensible habit of not keeping personal information longer than it is needed.

  • Outdated instructions stop misleading people

    Obsolete help messages are removed instead of being found and followed months later by someone who did not know they were out of date. Support staff spend less time correcting advice that was right last spring and wrong today.

  • No manual cleanup chore

    A moderator no longer needs to remember to clear bot-output channels by hand. The work happens at night when no one is chatting, so the clearing never interrupts a conversation or surprises anyone mid-sentence.

  • Rate-limit safe deletion

    Pausing between deletions avoids errors from Discord, so a large backlog is handled steadily over a night instead of failing partway. If a run is interrupted, the next night picks up whatever is left without anyone intervening.

How it works

What happens, step by step

  1. Every night, ClickRuntime goes through the messages in the Discord channel you chose.

  2. It finds messages older than the number of days you set.

  3. It deletes them, pausing as needed so Discord does not block the bot.

  4. A note is posted saying how many messages were removed.

Before it runs live

  • Connect Discord

What you get

RunsDaily
Clear out old messages every nighttoday, 9:00Succeeded
Discord · #bot-logsDeleted 86 messages older than 7 days.

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Run it at a different time, more or less often, or only on weekdays
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Discord steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
nightly_channel_cleanup.pyexample
from datetime import datetime, timedelta, timezone
from clickruntime import on_trigger, http, credentials

BOT_LOGS = "BOT_LOGS_CHANNEL_ID"

def discord(method, path, **kw):
    r = http.request(method, f"https://discord.com/api/v10{path}",
                     headers={"Authorization": f"Bot {credentials.secret('DISCORD_BOT_TOKEN')}"}, **kw)
    r.raise_for_status()
    return r.json() if r.content else None

@on_trigger
def run(event):
    now = datetime.now(timezone.utc)
    msgs = discord("GET", f"/channels/{BOT_LOGS}/messages", params={"limit": 100})
    old = [m for m in msgs if datetime.fromisoformat(m["timestamp"]) < now - timedelta(days=7)]
    bulk = [m["id"] for m in old if datetime.fromisoformat(m["timestamp"]) > now - timedelta(days=14)]
    if len(bulk) >= 2:
        discord("POST", f"/channels/{BOT_LOGS}/messages/bulk-delete", json={"messages": bulk})
    for m in old:
        if m["id"] not in bulk or len(bulk) < 2:
            discord("DELETE", f"/channels/{BOT_LOGS}/messages/{m['id']}")
    return {"deleted": len(old)}

FAQ

Common questions

Does it delete pinned messages?
Pinned messages can be kept by skipping them, which is the recommended setup for rules or key announcements. Tell your AI assistant to exclude pins when you set it up, otherwise old pinned messages are treated like any other message.
Can I choose how many days to keep?
Yes. The age limit is a single number you set, and it can differ per channel. A bot-log channel might keep one day of history, while a general support channel keeps thirty, so each space gets the retention that suits it.
What permissions does the bot need?
It needs permission to view the channel, read message history and manage messages. Without Manage Messages, deletion is refused, and the run log in the ClickRuntime dashboard shows exactly which channel failed so you can fix the role setting.
What permissions does it need?
Read Message History, Manage Messages. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it runs (daily). Checks that find nothing to do and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Clear out old messages every night” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.