未捕获的TypeError:无法读取未定义的Discord的属性“替换”

时间:2018-08-20 07:47:14

标签: javascript

脚本用于通过Discord利用顶部的ID删除邮件。运行脚本时出现错误Uncaught TypeError: Cannot read property 'replace' of undefined。似乎无法弄清楚如何解决我收到的错误。

var before = '336607993439453184';
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;
        return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {
          headers,
          method: 'DELETE'
        }));
      }));
    }).then(() => clearMessages());
}
clearMessages();

1 个答案:

答案 0 :(得分:0)

这是因为下面提到的代码是未定义

typeof document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token == undefined

您只能在字符串数据类型上使用替换功能

检查您的浏览器本地存储,以查看是否存在令牌