尝试删除不一致的消息时出错

时间:2018-11-11 20:04:07

标签: javascript discord

我是javascript新手。我试图使用以下代码删除不和谐频道中的所有消息。但是,我收到错误消息:

const authToken = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/"/g, "");

代码如下:

// Turn on Developer Mode under User Settings > Appearance > Developer Mode (at the bottom)
// Then open the channel you wish to delete all of the messages (could be a DM) and click the three dots on the far right.
// Click "Copy ID" and paste that instead of LAST_MESSAGE_ID.
// Copy / paste the below script into the JavaScript console.

var before = 'LAST_MESSAGE_ID';
var your_username = ''; //your username
var your_discriminator = ''; //that 4 digit code e.g. username#1234
var foundMessages = false;
clearMessages = function() {
  const authToken = document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token.replace(/"/g, "");
  const channel = window.location.href.split('/').pop();
  const baseURL = `https://discordapp.com/api/channels/${channel}/messages`;
  const headers = {
    "Authorization": authToken
  };

  let clock = 0;
  let interval = 500;

  function delay(duration) {
    return new Promise((resolve, reject) => {
      setTimeout(() => resolve(), duration);
    });
  }

  fetch(baseURL + '?before=' + before + '&limit=100', {
      headers
    })
    .then(resp => resp.json())
    .then(messages => {
      return Promise.all(messages.map((message) => {
        before = message.id;
        foundMessages = true;

        if (
          message.author.username == your_username &&
          message.author.discriminator == your_discriminator
        ) {
          return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {
            headers,
            method: 'DELETE'
          }));
        }
      }));
    }).then(() => {

      if (foundMessages) {
        foundMessages = false;
        clearMessages();
      } else {
        console.log('DONE CHECKING CHANNEL!!!')
      }

    });
}
clearMessages();

此代码安全吗?还是我在尝试以不和谐方式使用它时犯了一个严重的错误?

感谢您的帮助!

0 个答案:

没有答案