Skip to content

Instantly share code, notes, and snippets.

@victornpb
Last active April 9, 2026 02:50
Show Gist options
  • Select an option

  • Save victornpb/135f5b346dea4decfc8f63ad7d9cc182 to your computer and use it in GitHub Desktop.

Select an option

Save victornpb/135f5b346dea4decfc8f63ad7d9cc182 to your computer and use it in GitHub Desktop.

Revisions

  1. victornpb revised this gist Apr 29, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Delete all messages in a Discord channel or DM

    -----------------------------------------------------------------------
    #### This gist moved to https://github.com/victornpb/undiscord
    ## 👉 UPDATE: This gist moved to https://github.com/victornpb/undiscord
    -----------------------------------------------------------------------

    1. Open Discord in a browser like Chrome or Firefox;
  2. victornpb revised this gist Apr 29, 2022. 2 changed files with 3 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion deleteDiscordMessages.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@
    This file is now hosted here:
    https://github.com/victornpb/deleteDiscordMessages
    https://github.com/victornpb/undiscord
    */
    4 changes: 2 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    # Delete all messages in a Discord channel or DM

    -----------------------------------------------------------------------
    #### This gist moved to https://github.com/victornpb/deleteDiscordMessages
    #### This gist moved to https://github.com/victornpb/undiscord
    -----------------------------------------------------------------------

    1. Open Discord in a browser like Chrome or Firefox;

    2. Open DevTools pressing <kbd>F12</kbd> or <kbd>⌘ command</kbd>+<kbd>option</kbd>+<kbd>J</kbd>;

    3. Copy the [deleteDiscordMessages.js](https://github.com/victornpb/deleteDiscordMessages) script and paste it in the Console, then press <kbd>ENTER</kbd>;
    3. Copy the [deleteDiscordMessages.js](https://github.com/victornpb/undiscord) script and paste it in the Console, then press <kbd>ENTER</kbd>;

    4. A window will be opened, fill the variables and click the <button>START</button> button.

  3. victornpb revised this gist Dec 4, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Delete all messages in a Discord channel or DM

    -----------------------------------------------------------------------
    #### This gist moved to https://victornpb.github.io/deleteDiscordMessages/
    #### This gist moved to https://github.com/victornpb/deleteDiscordMessages
    -----------------------------------------------------------------------

    1. Open Discord in a browser like Chrome or Firefox;
  4. victornpb revised this gist Dec 4, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Delete all messages in a Discord channel or DM

    -----------------------------------------------------------------------
    #### This gist moved to https://github.com/victornpb/deleteDiscordMessages
    #### This gist moved to https://victornpb.github.io/deleteDiscordMessages/
    -----------------------------------------------------------------------

    1. Open Discord in a browser like Chrome or Firefox;
  5. victornpb revised this gist Aug 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@

    4. A window will be opened, fill the variables and click the <button>START</button> button.

    <img src="https://user-images.githubusercontent.com/3372598/63403726-f0f8e200-c3cf-11e9-97ef-d1e73a225027.png" height="300">
    <img src="https://user-images.githubusercontent.com/3372598/63647194-f158ec00-c6f3-11e9-9419-79cfb04e2399.png" height="600">


    ## Variables
  6. victornpb revised this gist Aug 21, 2019. 2 changed files with 14 additions and 179 deletions.
    160 changes: 4 additions & 156 deletions deleteDiscordMessages.js
    Original file line number Diff line number Diff line change
    @@ -1,159 +1,7 @@
    //Paste this function in DevTools console inside Discord
    /*
    /**
    * Delete all messages in a Discord channel or DM
    * @param {string} authToken Your authorization token
    * @param {string} authorId Author of the messages you want to delete
    * @param {string} channelId Channel were the messages are located
    * @param {string} afterMessageId Only delete messages after this, leave blank do delete all
    * @author Victornpb <https://www.github.com/victornpb>
    * @see https://gist.github.com/victornpb/135f5b346dea4decfc8f63ad7d9cc182
    */
    function deleteMessages(authToken, authorId, channelId, afterMessageId) {
    const start = new Date();
    let delayDelete = 500;
    let delaySearch = 1000;
    let delCount = 0;
    let failCount = 0;
    let estimatedPing = 220;
    let grandTotal;
    let throttledCount = 0;
    let throttledTotalTime = 0;
    const history = [];
    This file is now hosted here:
    const wait = async (ms) => new Promise(done => setTimeout(done, ms));
    const msToHMS = (s) => `${s / 3.6e6 | 0}h ${(s % 3.6e6) / 6e4 | 0}m ${(s % 6e4) / 1000 | 0}s`;
    function logger(type, args, style = '') {
    console[type].apply(console, args);
    history.push(args);
    pp.insertAdjacentHTML('beforeend', `<div style="${style}">${Array.from(args).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`);
    popup.scrollBy(0, 1e10);
    }
    function log() { logger('log', arguments, 'black'); }
    function log_info() { logger('info', arguments, 'color:darkturquoise;'); }
    function log_verb() { logger('debug', arguments, 'color:gray;'); }
    function log_warn() { logger('warn', arguments, 'color:orange;'); }
    function log_error() { logger('error', arguments, 'color:red;'); }
    function log_success() { logger('log', arguments, 'color:green;'); }
    https://github.com/victornpb/deleteDiscordMessages
    var popup = window.open('', '', 'width=800,height=1000,top=0,left=0');
    if (!popup) return console.error('Popup blocked! Please allow popups and try again.');
    popup.document.write('<span>...</span>');
    popup.document.body.innerHTML = '<pre></pre>';
    const pp = popup.document.getElementsByTagName('pre')[0];


    log_info(`Started at ${start.toLocaleString()}`);
    log(`channelId=${channelId} authorId=${authorId} firstMessageId=${afterMessageId}`);
    log_info(`---- You can abort by setting STOP=1 on the console ----`);
    recurse();

    async function recurse() {
    const headers = {
    "Authorization": authToken
    };
    const deleteAfter = `search?author_id=${authorId}` + (afterMessageId ? `&min_id=${afterMessageId}` : '');
    const baseURL = `https://discordapp.com/api/v6/channels/${channelId}/messages/`;

    let resp;
    try {
    resp = await fetch(baseURL + deleteAfter, {
    headers
    });
    } catch (err) {
    log_error('Something went wrong!', err);
    return;
    }

    // not indexed yet
    if (resp.status === 202) {
    const w = (await resp.json()).retry_after;
    throttledCount++;
    throttledTotalTime += w;
    log_warn(`This channel wasn't indexed, waiting ${w} ms for discord to index it...`);
    await wait(w);
    return recurse();
    }

    if (!resp.ok) {
    if (resp.status === 429) {
    const r = await resp.json();
    const x = r.retry_after;
    throttledCount++;
    throttledTotalTime += x;
    log_warn(`! Rate limited by the API! Waiting ${x} ms ...`);
    await wait(x);
    return recurse();
    } else {
    log_error('API respondend with non OK status!', await resp.json());
    return;
    }
    }

    const result = await resp.json();

    const total = result.total_results;
    if (!grandTotal) grandTotal = total;
    log_info(`Messages to delete: ${result.total_results}`, `Time remaining: ${msToHMS((delaySearch * Math.round(total / 25)) + ((delayDelete + estimatedPing) * total))} (ping: ${estimatedPing << 0}ms)`);

    if (result.total_results > 0) {
    for (let i = 0; i < result.messages.length; i++) {
    const element = result.messages[i];
    for (let j = 0; j < element.length; j++) {
    const message = element[j];

    if (window.STOP) return log_error('STOPPED! (If you want to continue set STOP=0 and run again!');

    if (message.type === 3) {
    log_verb('Found a System message!? skipping it...', message);
    } else if (message.author.id == authorId && message.hit == true) {

    log(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal}) Deleting ID:${message.id}`,
    `[${new Date(message.timestamp).toLocaleString()}] ${message.author.username}#${message.author.discriminator}: ${message.content}`,
    message.attachments.length ? message.attachments : '');
    const s = Date.now();

    let resp;
    try {
    resp = await fetch(baseURL + message.id, {
    headers,
    method: "DELETE"
    });
    delCount++;
    } catch (err) {
    log_error('Failed to delete message:', message, 'Error:', err);
    failCount++;
    }

    if (!resp.ok) {
    if (resp.status === 429) {
    const r = await resp.json();
    const x = r.retry_after;
    throttledCount++;
    throttledTotalTime += x;
    log_warn(`! Rate limited by the API! Waiting ${x} ms ...`);
    await wait(x);
    i--;
    } else {
    log_error('API respondend with non OK status!', resp);
    }
    }
    estimatedPing = (estimatedPing + (Date.now() - s)) / 2;
    await wait(delayDelete);
    }
    }
    }
    log_verb('Getting next messages...');
    await wait(delaySearch);
    return recurse();
    } else {
    log_success('---- DONE! ----');
    log_info(`Ended at ${new Date().toLocaleString()}! Total time: ${msToHMS(Date.now() - start.getTime())}`);
    log(`Rate Limited: ${throttledCount} times. Total time throttled: ${msToHMS(throttledTotalTime)}`);
    log(`Deleted ${delCount} messages , ${failCount} failed.`);
    return result;
    }
    }
    }

    //END.
    */
    33 changes: 10 additions & 23 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,31 +1,18 @@
    # Delete all messages in a Discord channel or DM

    -----------------------------------------------------------------------
    #### This gist moved to https://github.com/victornpb/deleteDiscordMessages
    -----------------------------------------------------------------------

    1. Open Discord in a browser like Chrome or Firefox;

    2. Open DevTools pressing <kbd>F12</kbd> or <kbd>⌘ command</kbd>+<kbd>option</kbd>+<kbd>J</kbd>;

    3. Copy the [deleteDiscordMessages.js](#file-deletediscordmessages-js) script and paste it in the Console, then press <kbd>ENTER</kbd>;

    4. Edit the following text, then paste it in the console:

    **Continue reading for [instructions](#Variables) on how edit each variable**

    ```js
    // fill with your info
    var authToken = "MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk";
    var authorId = "112233445566778899";
    var channelId = "112233445566778899";
    var firstMessageId = "";
    3. Copy the [deleteDiscordMessages.js](https://github.com/victornpb/deleteDiscordMessages) script and paste it in the Console, then press <kbd>ENTER</kbd>;

    deleteMessages(authToken, authorId, channelId, firstMessageId); //start
    ```
    *I recommend that you paste it inside a text editor, change it and then paste it in the console.*
    5. It will start to delete messages. You will be able to follow the progress and the remaining time in a popup window.
    **Do not close this window while it is running!**
    <img src="https://user-images.githubusercontent.com/3372598/55703780-ec97d380-59b0-11e9-93e6-73983cb32de5.png" height="300">

    #### Abort / Stop
    Inside the **console**, type (uppercase) `STOP=1` and press <kbd>ENTER</kbd>.
    4. A window will be opened, fill the variables and click the <button>START</button> button.

    <img src="https://user-images.githubusercontent.com/3372598/63403726-f0f8e200-c3cf-11e9-97ef-d1e73a225027.png" height="300">


    ## Variables
    @@ -61,7 +48,7 @@ Inside the **console**, type (uppercase) `STOP=1` and press <kbd>ENTER</kbd>.

    ----
    #### DeveloperMode
    If the `Copy ID` menu doens't show up when right clicking:
    If the `Copy ID` menu doesn't show up when right clicking:
    - Enable developer mode in discord
    Go to user **Settings** > **Appearance** in discord and enable **Developer mode**.
    <img src="https://user-images.githubusercontent.com/3372598/58374693-fa3df400-7f31-11e9-9abd-ba17b9440326.png" height="50">
    @@ -81,4 +68,4 @@ If you are unsure do not share screenshots, or copy paste logs on the internet.
    >
    > By using any code or information provided here you are agreeing to all parts of the above Disclaimer.
    Last tested: 2019-MAY-25
    Last tested: 2019-AUG-21
  7. victornpb revised this gist Jul 19, 2019. 1 changed file with 12 additions and 3 deletions.
    15 changes: 12 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -67,9 +67,18 @@ If the `Copy ID` menu doens't show up when right clicking:
    <img src="https://user-images.githubusercontent.com/3372598/58374693-fa3df400-7f31-11e9-9abd-ba17b9440326.png" height="50">
    ----
    DO NOT SHARE YOUR `authToken` !
    ----
    # DO NOT SHARE YOUR `authToken`!
    Sharing your authToken on the internet will give full access to your account! [There are bots gathering credentials all over the internet](https://github.com/rndinfosecguy/Scavenger).
    If you post your token by accident, LOGOUT from discord on that **same browser** you got that token imediately.
    Changing your password will make sure that you get logged out of every device. I advice that you turn on [2FA](https://support.discordapp.com/hc/en-us/articles/219576828-Setting-up-Two-Factor-Authentication) afterwards.
    **DISCLAIMER:** *USE AT YOUR OWN RISK! I TAKE NO RESPONSABILITY FOR ANYTHING POSTED HERE!*
    If you are unsure do not share screenshots, or copy paste logs on the internet.
    ----
    > **DISCLAIMER:**
    > THE SOFTWARE AND ALL INFORMATION HERE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    >
    > By using any code or information provided here you are agreeing to all parts of the above Disclaimer.
    Last tested: 2019-MAY-25
  8. victornpb revised this gist Jun 25, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion deleteDiscordMessages.js
    Original file line number Diff line number Diff line change
    @@ -37,9 +37,11 @@ function deleteMessages(authToken, authorId, channelId, afterMessageId) {
    function log_success() { logger('log', arguments, 'color:green;'); }

    var popup = window.open('', '', 'width=800,height=1000,top=0,left=0');
    if (!popup) return console.error('Popup blocked! Please allow popups and try again.');
    popup.document.write('<span>...</span>');
    popup.document.body.innerHTML = '<pre></pre>';
    const pp = popup.document.getElementsByTagName('pre')[0];
    if (!popup) console.error('Popup blocked!');


    log_info(`Started at ${start.toLocaleString()}`);
    log(`channelId=${channelId} authorId=${authorId} firstMessageId=${afterMessageId}`);
  9. victornpb revised this gist May 26, 2019. 1 changed file with 149 additions and 91 deletions.
    240 changes: 149 additions & 91 deletions deleteDiscordMessages.js
    Original file line number Diff line number Diff line change
    @@ -1,99 +1,157 @@
    //Paste this function in DevTools console inside Discord

    function deleteMessages(authToken, authorId, channelId, firstMessageId) {
    const start = new Date();
    const delayDelete = 500;
    const delaySearch = 1000;
    let delCount = 0;
    let failCount = 0;
    let estimatedPing = 220;
    let grandTotal;
    const history = [];

    const wait = async (ms) => new Promise(done => setTimeout(done, ms));
    const msToHMS = (s) => `${s / 3.6e6 | 0}h ${(s % 3.6e6) / 6e4 | 0}m ${(s % 6e4) / 1000 | 0}s`;

    function log() { history.push(arguments); console.log.apply(console, arguments); pp.insertAdjacentHTML('beforeend', `<div style='color:black;'>${Array.from(arguments).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`); popup.scrollBy(0, 1e10); };
    function error() { history.push(arguments); console.error.apply(console, arguments); pp.insertAdjacentHTML('beforeend', `<div style='color:red;'>${Array.from(arguments).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`); popup.scrollBy(0, 1e10); };
    var popup = window.open('', '', 'width=800,height=1000,top=0,left=0');
    popup.document.body.innerHTML = '<pre></pre>';
    const pp = popup.document.getElementsByTagName('pre')[0];
    if (!popup) console.error('Popup blocked!');

    log(`---- You can abort by setting STOP=1 on the console ----`);
    log(`Starting at ${start}, channelId=${channelId} authorId=${authorId} firstMessageId=${firstMessageId}`);
    recurse();

    async function recurse() {
    const headers = {
    "Authorization": authToken
    };
    const deleteAfter = `search?author_id=${authorId}` + (firstMessageId ? `&min_id=${firstMessageId}` : '');
    const baseURL = `https://discordapp.com/api/v6/channels/${channelId}/messages/`;

    let resp;
    try {
    resp = await fetch(baseURL + deleteAfter, {
    headers
    });
    /**
    * Delete all messages in a Discord channel or DM
    * @param {string} authToken Your authorization token
    * @param {string} authorId Author of the messages you want to delete
    * @param {string} channelId Channel were the messages are located
    * @param {string} afterMessageId Only delete messages after this, leave blank do delete all
    * @author Victornpb <https://www.github.com/victornpb>
    * @see https://gist.github.com/victornpb/135f5b346dea4decfc8f63ad7d9cc182
    */
    function deleteMessages(authToken, authorId, channelId, afterMessageId) {
    const start = new Date();
    let delayDelete = 500;
    let delaySearch = 1000;
    let delCount = 0;
    let failCount = 0;
    let estimatedPing = 220;
    let grandTotal;
    let throttledCount = 0;
    let throttledTotalTime = 0;
    const history = [];

    const wait = async (ms) => new Promise(done => setTimeout(done, ms));
    const msToHMS = (s) => `${s / 3.6e6 | 0}h ${(s % 3.6e6) / 6e4 | 0}m ${(s % 6e4) / 1000 | 0}s`;
    function logger(type, args, style = '') {
    console[type].apply(console, args);
    history.push(args);
    pp.insertAdjacentHTML('beforeend', `<div style="${style}">${Array.from(args).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`);
    popup.scrollBy(0, 1e10);
    }
    catch (err) {
    error('Something went wrong!', err);
    return;
    }
    const result = await resp.json();

    const total = result.total_results;
    if (!grandTotal) grandTotal = total;
    log(`Messages to delete: ${result.total_results}`, `Time remaining: ${msToHMS((delaySearch * Math.round(total / 25)) + ((delayDelete + estimatedPing) * total))} (ping: ${estimatedPing << 0}ms)`);

    if (result.total_results > 0) {
    for (let i = 0; i < result.messages.length; i++) {
    const element = result.messages[i];
    for (let j = 0; j < element.length; j++) {
    const message = element[j];

    if (window.STOP) return error('STOPPED! (If you want to continue set STOP=0 and run again!');

    if (message.type === 3) {
    log('System message?', message);
    }
    else if (message.author.id == authorId && message.hit == true) {

    log(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal}) Deleting ID:${message.id}`,
    `[${new Date(message.timestamp).toLocaleString()}] ${message.author.username}#${message.author.discriminator}: ${message.content}`,
    message.attachments.length ? message.attachments : '');
    const s = Date.now();
    try {
    await fetch(baseURL + message.id, {
    headers,
    method: "DELETE"
    });
    delCount++;
    } catch (err) {
    error('Failed to delete message:', message, 'Error:', err);
    failCount++;
    }
    estimatedPing = (estimatedPing + (Date.now() - s)) / 2;
    await wait(delayDelete);
    }
    function log() { logger('log', arguments, 'black'); }
    function log_info() { logger('info', arguments, 'color:darkturquoise;'); }
    function log_verb() { logger('debug', arguments, 'color:gray;'); }
    function log_warn() { logger('warn', arguments, 'color:orange;'); }
    function log_error() { logger('error', arguments, 'color:red;'); }
    function log_success() { logger('log', arguments, 'color:green;'); }

    var popup = window.open('', '', 'width=800,height=1000,top=0,left=0');
    popup.document.body.innerHTML = '<pre></pre>';
    const pp = popup.document.getElementsByTagName('pre')[0];
    if (!popup) console.error('Popup blocked!');

    log_info(`Started at ${start.toLocaleString()}`);
    log(`channelId=${channelId} authorId=${authorId} firstMessageId=${afterMessageId}`);
    log_info(`---- You can abort by setting STOP=1 on the console ----`);
    recurse();

    async function recurse() {
    const headers = {
    "Authorization": authToken
    };
    const deleteAfter = `search?author_id=${authorId}` + (afterMessageId ? `&min_id=${afterMessageId}` : '');
    const baseURL = `https://discordapp.com/api/v6/channels/${channelId}/messages/`;

    let resp;
    try {
    resp = await fetch(baseURL + deleteAfter, {
    headers
    });
    } catch (err) {
    log_error('Something went wrong!', err);
    return;
    }
    }
    log('Getting next messages...');
    await wait(delaySearch);
    return recurse();
    }
    else {
    const msg = `Everything is clear!\n Messages deleted: ${delCount} Failed: ${failCount} \n Total time: ${msToHMS(Date.now() - start.getTime())}`;
    log(msg);
    return result;
    }
    }
    }


    //END.

    // not indexed yet
    if (resp.status === 202) {
    const w = (await resp.json()).retry_after;
    throttledCount++;
    throttledTotalTime += w;
    log_warn(`This channel wasn't indexed, waiting ${w} ms for discord to index it...`);
    await wait(w);
    return recurse();
    }

    if (!resp.ok) {
    if (resp.status === 429) {
    const r = await resp.json();
    const x = r.retry_after;
    throttledCount++;
    throttledTotalTime += x;
    log_warn(`! Rate limited by the API! Waiting ${x} ms ...`);
    await wait(x);
    return recurse();
    } else {
    log_error('API respondend with non OK status!', await resp.json());
    return;
    }
    }

    const result = await resp.json();

    const total = result.total_results;
    if (!grandTotal) grandTotal = total;
    log_info(`Messages to delete: ${result.total_results}`, `Time remaining: ${msToHMS((delaySearch * Math.round(total / 25)) + ((delayDelete + estimatedPing) * total))} (ping: ${estimatedPing << 0}ms)`);

    if (result.total_results > 0) {
    for (let i = 0; i < result.messages.length; i++) {
    const element = result.messages[i];
    for (let j = 0; j < element.length; j++) {
    const message = element[j];

    if (window.STOP) return log_error('STOPPED! (If you want to continue set STOP=0 and run again!');

    if (message.type === 3) {
    log_verb('Found a System message!? skipping it...', message);
    } else if (message.author.id == authorId && message.hit == true) {

    log(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal}) Deleting ID:${message.id}`,
    `[${new Date(message.timestamp).toLocaleString()}] ${message.author.username}#${message.author.discriminator}: ${message.content}`,
    message.attachments.length ? message.attachments : '');
    const s = Date.now();

    let resp;
    try {
    resp = await fetch(baseURL + message.id, {
    headers,
    method: "DELETE"
    });
    delCount++;
    } catch (err) {
    log_error('Failed to delete message:', message, 'Error:', err);
    failCount++;
    }

    if (!resp.ok) {
    if (resp.status === 429) {
    const r = await resp.json();
    const x = r.retry_after;
    throttledCount++;
    throttledTotalTime += x;
    log_warn(`! Rate limited by the API! Waiting ${x} ms ...`);
    await wait(x);
    i--;
    } else {
    log_error('API respondend with non OK status!', resp);
    }
    }
    estimatedPing = (estimatedPing + (Date.now() - s)) / 2;
    await wait(delayDelete);
    }
    }
    }
    log_verb('Getting next messages...');
    await wait(delaySearch);
    return recurse();
    } else {
    log_success('---- DONE! ----');
    log_info(`Ended at ${new Date().toLocaleString()}! Total time: ${msToHMS(Date.now() - start.getTime())}`);
    log(`Rate Limited: ${throttledCount} times. Total time throttled: ${msToHMS(throttledTotalTime)}`);
    log(`Deleted ${delCount} messages , ${failCount} failed.`);
    return result;
    }
    }
    }

    //END.
  10. victornpb revised this gist May 25, 2019. 1 changed file with 49 additions and 37 deletions.
    86 changes: 49 additions & 37 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -2,62 +2,74 @@

    1. Open Discord in a browser like Chrome or Firefox;

    2. Open DevTools pressing <kbd>F12</kbd> or <kbd>CMD</kbd>+<kbd>OPTION</kbd>+<kbd>J</kbd>;
    2. Open DevTools pressing <kbd>F12</kbd> or <kbd>⌘ command</kbd>+<kbd>option</kbd>+<kbd>J</kbd>;

    3. Copy the [deleteMessages.js](https://gist.github.com/victornpb/135f5b346dea4decfc8f63ad7d9cc182#file-deletemessages-js) script and paste it in the Console and press ENTER;
    3. Copy the [deleteDiscordMessages.js](#file-deletediscordmessages-js) script and paste it in the Console, then press <kbd>ENTER</kbd>;

    4. Edit the following variables, then paste it in the console:
    4. Edit the following text, then paste it in the console:

    **Continue reading for [instructions](#Variables) on how edit each variable**

    ```js
    // Your token, you can find it in other requests headers
    var authToken = "NabcdefghiU4NDY5ODI2NTY.KXx1ab.aU8FUz9fOABxdsi1LYORJuv666f";

    // Right click your avatar in any chat, Copy ID
    // fill with your info
    var authToken = "MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk";
    var authorId = "112233445566778899";

    // Right click a channel or DM, Copy ID
    var channelId = "112233445566778899";

    // Delete all messages after this one, (leave blank to delete all your messages in a channel)
    var firstMessageId = "";


    deleteMessages(authToken, authorId, channelId, firstMessageId); //start
    ```
    *I recommend that you paste it inside a text editor, change it and then paste it in the console.*
    5. It will start to delete messages. You will be able to follow the progress and the remaining time in a popup window.
    **Do not close this window while it is running!**
    <img src="https://user-images.githubusercontent.com/3372598/55703780-ec97d380-59b0-11e9-93e6-73983cb32de5.png" height="300">

    #### Abort / Stop
    Inside the **console**, type (uppercase) `STOP=1` and press <kbd>ENTER</kbd>.


    ## Variables
    >
    > ### authToken
    > <img src="https://user-images.githubusercontent.com/3372598/58374446-e5f7f800-7f2d-11e9-9db0-d1a723571d6d.png" width="100%">
    >
    > 1. Open the dev tools (F12), open the Network tab. (You should clear all requests for better readability if you see some.)
    > 2. Delete one message manually. In the request log, you will see a request with a DELETE method.
    > 3. Click on the request to open the details, and on the Headers tab, copy the 'authorization' token. It's a long text > with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`.
    >
    > ### authorId
    > - Right click your **avatar** in a message you sent in the chat, [Copy ID](#DeveloperMode)
    > <img src="https://media.giphy.com/media/YnNTRqKRxVcjOuyFps/giphy.gif">
    > NOT THE MESSAGE THE AVATAR.
    > (You cannot delete the other's person messages a in DM channel, you will get Error 403)
    >
    > ### channelId
    > - **For public channels:** Right click a channel, [Copy ID](#DeveloperMode)
    > <img src=https://media.giphy.com/media/UqBPG05BIP3Vkj7Pby/giphy.gif>
    > - **For a DM/Direct messages:** copy the number after /@me/ in the URL)
    > <img src="https://user-images.githubusercontent.com/3372598/58374439-d9739f80-7f2d-11e9-85f4-3c241a85a8bb.png" height="200">
    >
    > ### firstMessageId
    > - Delete messages after one message:
    > Right click a message, [Copy ID](#DeveloperMode)
    > <img src="https://user-images.githubusercontent.com/3372598/58374442-daa4cc80-7f2d-11e9-843b-10aec30fe349.png" height="250">
    > - Delete since the begining of a channel:
    > Leave this variable empty `""`.

    #### authToken
    - Open the dev tools (F12), open the Network tab. (You should clear all requests for better readability if you see some.)
    - Delete one message manually. In the request log, you will see a request with a DELETE method.
    - Click on the request to open the details, and on the Headers tab, copy the 'authorization' token. It's a long text with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`.
    #### authorId
    - Right click your avatar in any chat, Copy ID
    #### channelId
    - Right click a channel, Copy ID, For DM copy the number after /@me/ in the URL

    #### firstMessageId
    - Right click a message, Copy ID (Leave this variable empty for deleting all your messages in a channel)
    <br>

    > **NOTE:** if the `Copy ID` menu doens't show up when right clicking
    > Enable developer mode in discord
    > Go to user **Settings** > **Appearance** in discord and enable **Developer mode**.


    5. The script will start to run, a popup will be opened showing the progress and the messages being deleted, as well as a remaining time. Do not close it.

    ![Screen Shot 2019-04-08](https://user-images.githubusercontent.com/3372598/55703780-ec97d380-59b0-11e9-93e6-73983cb32de5.png)

    ----

    You can stop the process by typing `STOP=1` in the console (UPPERCASE) and pressing ENTER.
    #### DeveloperMode
    If the `Copy ID` menu doens't show up when right clicking:
    - Enable developer mode in discord
    Go to user **Settings** > **Appearance** in discord and enable **Developer mode**.
    <img src="https://user-images.githubusercontent.com/3372598/58374693-fa3df400-7f31-11e9-9abd-ba17b9440326.png" height="50">
    ----
    DO NOT SHARE YOUR `authToken` !
    ----
    **DISCLAIMER:** *USE AT YOUR OWN RISK! I TAKE NO RESPONSABILITY FOR ANYTHING POSTED HERE!*
    Tested: 2019-APRIL
    Last tested: 2019-MAY-25
  11. victornpb renamed this gist Apr 15, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  12. victornpb revised this gist Apr 8, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -48,6 +48,8 @@

    5. The script will start to run, a popup will be opened showing the progress and the messages being deleted, as well as a remaining time. Do not close it.

    ![Screen Shot 2019-04-08](https://user-images.githubusercontent.com/3372598/55703780-ec97d380-59b0-11e9-93e6-73983cb32de5.png)

    ----

    You can stop the process by typing `STOP=1` in the console (UPPERCASE) and pressing ENTER.
  13. victornpb revised this gist Apr 8, 2019. 1 changed file with 12 additions and 6 deletions.
    18 changes: 12 additions & 6 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    # Delete all messages in a Discord channel or DM

    1. Open discord in a browser
    1. Open Discord in a browser like Chrome or Firefox;

    2. Open DevTools pressing F12 or CMD-OPTION-J
    2. Open DevTools pressing <kbd>F12</kbd> or <kbd>CMD</kbd>+<kbd>OPTION</kbd>+<kbd>J</kbd>;

    3. Paste the **deleteMessages.js** script in the Console and press ENTER
    3. Copy the [deleteMessages.js](https://gist.github.com/victornpb/135f5b346dea4decfc8f63ad7d9cc182#file-deletemessages-js) script and paste it in the Console and press ENTER;

    4. Edit and paste the following variables:
    4. Edit the following variables, then paste it in the console:

    ```js
    // Your token, you can find it in other requests headers
    @@ -39,13 +39,19 @@
    #### firstMessageId
    - Right click a message, Copy ID (Leave this variable empty for deleting all your messages in a channel)
    .
    <br>
    > **NOTE:** if the `Copy ID` menu doens't show up when right clicking
    > Enable developer mode in discord
    > Go to user **Settings** > **Appearance** in discord and enable **Developer mode**.


    5. The script will start to run, a popup will be opened showing the progress and the messages being deleted, as well as a remaining time. Do not close it.

    ----

    You can stop the process by typing `STOP=1` in the console (UPPERCASE) and pressing ENTER.

    ----
    DO NOT SHARE YOUR `authToken` !
    ----
  14. victornpb revised this gist Apr 8, 2019. 2 changed files with 7 additions and 2 deletions.
    7 changes: 6 additions & 1 deletion deleteMessages.js
    Original file line number Diff line number Diff line change
    @@ -91,4 +91,9 @@ function deleteMessages(authToken, authorId, channelId, firstMessageId) {
    }
    }

    //END

    //END.




    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@
    #### authToken
    - Open the dev tools (F12), open the Network tab. (You should clear all requests for better readability if you see some.)
    - Delete one message manually. In the request log, you will see a request with a DELETE method.
    - Click on the request to open the details, and on the Headers tab, copy the 'authorization' thoken. It's a long text with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`.
    - Click on the request to open the details, and on the Headers tab, copy the 'authorization' token. It's a long text with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`.
    #### authorId
    - Right click your avatar in any chat, Copy ID
  15. victornpb revised this gist Apr 8, 2019. 3 changed files with 56 additions and 14 deletions.
    2 changes: 2 additions & 0 deletions deleteMessages.js
    Original file line number Diff line number Diff line change
    @@ -90,3 +90,5 @@ function deleteMessages(authToken, authorId, channelId, firstMessageId) {
    }
    }
    }

    //END
    54 changes: 54 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,55 @@
    # Delete all messages in a Discord channel or DM

    1. Open discord in a browser

    2. Open DevTools pressing F12 or CMD-OPTION-J

    3. Paste the **deleteMessages.js** script in the Console and press ENTER

    4. Edit and paste the following variables:

    ```js
    // Your token, you can find it in other requests headers
    var authToken = "NabcdefghiU4NDY5ODI2NTY.KXx1ab.aU8FUz9fOABxdsi1LYORJuv666f";

    // Right click your avatar in any chat, Copy ID
    var authorId = "112233445566778899";

    // Right click a channel or DM, Copy ID
    var channelId = "112233445566778899";

    // Delete all messages after this one, (leave blank to delete all your messages in a channel)
    var firstMessageId = "";


    deleteMessages(authToken, authorId, channelId, firstMessageId); //start
    ```

    #### authToken
    - Open the dev tools (F12), open the Network tab. (You should clear all requests for better readability if you see some.)
    - Delete one message manually. In the request log, you will see a request with a DELETE method.
    - Click on the request to open the details, and on the Headers tab, copy the 'authorization' thoken. It's a long text with dots like `MTX5MzQ1MjAyMjU0NjA2MzM2.ROFLMAO.UvqZqBMXLpDuOY3Z456J3JRIfbk`.
    #### authorId
    - Right click your avatar in any chat, Copy ID
    #### channelId
    - Right click a channel, Copy ID, For DM copy the number after /@me/ in the URL
    #### firstMessageId
    - Right click a message, Copy ID (Leave this variable empty for deleting all your messages in a channel)
    .
    > **NOTE:** if the `Copy ID` menu doens't show up when right clicking
    > Enable developer mode in discord
    > Go to user **Settings** > **Appearance** in discord and enable **Developer mode**.

    ----
    DO NOT SHARE YOUR `authToken` !
    ----

    **DISCLAIMER:** *USE AT YOUR OWN RISK! I TAKE NO RESPONSABILITY FOR ANYTHING POSTED HERE!*

    Tested: 2019-APRIL
    14 changes: 0 additions & 14 deletions run.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +0,0 @@
    //Your token, you can find it in other requests headers
    var authToken = "NabcdefghiU4NDY5ODI2NTY.KXx1ab.aU8FUz9fOABxdsi1LYORJuv666f";

    //Right click your avatar in any chat, Copy ID
    var authorId = "112233445566778899";

    //Right click a channel or DM, Copy ID
    var channelId = "112233445566778899";

    //Delete all messages after this one, (leave blank to delete all your messages in a channel)
    var firstMessageId = "";

    //start
    deleteMessages(authToken, authorId, channelId, firstMessageId);
  16. victornpb revised this gist Apr 8, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Delete all messages in a Discord channel or DM
  17. victornpb created this gist Apr 8, 2019.
    92 changes: 92 additions & 0 deletions deleteMessages.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,92 @@
    //Paste this function in DevTools console inside Discord

    function deleteMessages(authToken, authorId, channelId, firstMessageId) {
    const start = new Date();
    const delayDelete = 500;
    const delaySearch = 1000;
    let delCount = 0;
    let failCount = 0;
    let estimatedPing = 220;
    let grandTotal;
    const history = [];

    const wait = async (ms) => new Promise(done => setTimeout(done, ms));
    const msToHMS = (s) => `${s / 3.6e6 | 0}h ${(s % 3.6e6) / 6e4 | 0}m ${(s % 6e4) / 1000 | 0}s`;

    function log() { history.push(arguments); console.log.apply(console, arguments); pp.insertAdjacentHTML('beforeend', `<div style='color:black;'>${Array.from(arguments).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`); popup.scrollBy(0, 1e10); };
    function error() { history.push(arguments); console.error.apply(console, arguments); pp.insertAdjacentHTML('beforeend', `<div style='color:red;'>${Array.from(arguments).map(o => typeof o === 'object' ? JSON.stringify(o) : o).join('\t')}</div>`); popup.scrollBy(0, 1e10); };
    var popup = window.open('', '', 'width=800,height=1000,top=0,left=0');
    popup.document.body.innerHTML = '<pre></pre>';
    const pp = popup.document.getElementsByTagName('pre')[0];
    if (!popup) console.error('Popup blocked!');

    log(`---- You can abort by setting STOP=1 on the console ----`);
    log(`Starting at ${start}, channelId=${channelId} authorId=${authorId} firstMessageId=${firstMessageId}`);
    recurse();

    async function recurse() {
    const headers = {
    "Authorization": authToken
    };
    const deleteAfter = `search?author_id=${authorId}` + (firstMessageId ? `&min_id=${firstMessageId}` : '');
    const baseURL = `https://discordapp.com/api/v6/channels/${channelId}/messages/`;

    let resp;
    try {
    resp = await fetch(baseURL + deleteAfter, {
    headers
    });
    }
    catch (err) {
    error('Something went wrong!', err);
    return;
    }
    const result = await resp.json();

    const total = result.total_results;
    if (!grandTotal) grandTotal = total;
    log(`Messages to delete: ${result.total_results}`, `Time remaining: ${msToHMS((delaySearch * Math.round(total / 25)) + ((delayDelete + estimatedPing) * total))} (ping: ${estimatedPing << 0}ms)`);

    if (result.total_results > 0) {
    for (let i = 0; i < result.messages.length; i++) {
    const element = result.messages[i];
    for (let j = 0; j < element.length; j++) {
    const message = element[j];

    if (window.STOP) return error('STOPPED! (If you want to continue set STOP=0 and run again!');

    if (message.type === 3) {
    log('System message?', message);
    }
    else if (message.author.id == authorId && message.hit == true) {

    log(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal}) Deleting ID:${message.id}`,
    `[${new Date(message.timestamp).toLocaleString()}] ${message.author.username}#${message.author.discriminator}: ${message.content}`,
    message.attachments.length ? message.attachments : '');
    const s = Date.now();
    try {
    await fetch(baseURL + message.id, {
    headers,
    method: "DELETE"
    });
    delCount++;
    } catch (err) {
    error('Failed to delete message:', message, 'Error:', err);
    failCount++;
    }
    estimatedPing = (estimatedPing + (Date.now() - s)) / 2;
    await wait(delayDelete);
    }
    }
    }
    log('Getting next messages...');
    await wait(delaySearch);
    return recurse();
    }
    else {
    const msg = `Everything is clear!\n Messages deleted: ${delCount} Failed: ${failCount} \n Total time: ${msToHMS(Date.now() - start.getTime())}`;
    log(msg);
    return result;
    }
    }
    }
    14 changes: 14 additions & 0 deletions run.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    //Your token, you can find it in other requests headers
    var authToken = "NabcdefghiU4NDY5ODI2NTY.KXx1ab.aU8FUz9fOABxdsi1LYORJuv666f";

    //Right click your avatar in any chat, Copy ID
    var authorId = "112233445566778899";

    //Right click a channel or DM, Copy ID
    var channelId = "112233445566778899";

    //Delete all messages after this one, (leave blank to delete all your messages in a channel)
    var firstMessageId = "";

    //start
    deleteMessages(authToken, authorId, channelId, firstMessageId);