Skip to content

Instantly share code, notes, and snippets.

@yuuslokrobjakkroval
Created April 12, 2026 16:27
Show Gist options
  • Select an option

  • Save yuuslokrobjakkroval/98aaaa785b3f25f5fea653b9a22e9cef to your computer and use it in GitHub Desktop.

Select an option

Save yuuslokrobjakkroval/98aaaa785b3f25f5fea653b9a22e9cef to your computer and use it in GitHub Desktop.

Discord DM Cleaner Script

A script to delete your own messages from a Discord DM channel.

How to Use

  1. Open Discord in your browser
  2. Open the browser's Developer Console (F12 → Console tab)
  3. Fill in your Token, DM Channel ID, and User ID
  4. Paste and run the script

⚠️ Warning: Using self-bot tokens violates Discord's Terms of Service. Use at your own risk.


Script

(async () => {
    // PASTE YOUR TOKEN BETWEEN THE QUOTES
    const token = "PASTE_TOKEN_HERE";

    // DM CHANNEL ID (from the URL)
    const dmChannelId = "1476759430493376676";

    // YOUR USER ID (Right-click your profile and copy the ID)
    const myUserId = "YOUR_USER_ID_HERE";

    const delay = 1200;

    async function clearDM() {
        const response = await fetch(`https://discord.com/api/v9/channels/${dmChannelId}/messages?limit=100`, {
            headers: { "Authorization": token }
        });

        const messages = await response.json();

        if (!Array.isArray(messages)) {
            console.error("Error fetching messages. Check your Token!");
            return;
        }

        const myMessages = messages.filter(m => m.author.id === myUserId);

        if (myMessages.length === 0) return console.log("No messages from you found in this batch.");

        for (const msg of myMessages) {
            await fetch(`https://discord.com/api/v9/channels/${dmChannelId}/messages/${msg.id}`, {
                method: "DELETE",
                headers: { "Authorization": token }
            });
            console.log(`Message deleted.`);
            await new Promise(res => setTimeout(res, delay));
        }
        console.log("Batch complete! If there are still messages, run the script again.");
    }

    clearDM();
})();

Notes

  • The script deletes up to 100 messages per run. If you have more, run it again.
  • The delay (1200ms) helps avoid Discord rate limits. Don't lower it too much.
  • Never share your token with anyone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment