Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:无法读取属性';更换';不和谐的_Javascript - Fatal编程技术网

Javascript 未捕获类型错误:无法读取属性';更换';不和谐的

Javascript 未捕获类型错误:无法读取属性';更换';不和谐的,javascript,Javascript,脚本用于使用顶部的ID通过Discord删除消息。当我运行脚本时,我得到一个错误uncaughttypeerror:cannotread属性'replace'of undefined。似乎不知道如何修复我得到的错误 var-before='336607993439453184'; clearMessages=函数(){ const authToken=document.body.appendChild(document.createElement`iframe`).contentWindow.

脚本用于使用顶部的ID通过Discord删除消息。当我运行脚本时,我得到一个错误
uncaughttypeerror:cannotread属性'replace'of undefined
。似乎不知道如何修复我得到的错误

var-before='336607993439453184';
clearMessages=函数(){
const authToken=document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/“/g,”);
const channel=window.location.href.split('/').pop();
常量baseURL=`https://discordapp.com/api/channels/${channel}/messages`;
常量头={
“授权”:authToken
};
设时钟=0;
设间隔=500;
功能延迟(持续时间){
返回新承诺((解决、拒绝)=>{
setTimeout(()=>resolve(),持续时间);
});
}
获取(baseURL+'-before='+before+'&limit=100'{
标题
})
.then(resp=>resp.json())
。然后(消息=>{
返回Promise.all(messages.map)((message)=>{
before=message.id;
返回延迟(时钟+=间隔)。然后(()=>fetch(`${baseURL}/${message.id}`{
标题,
方法:“删除”
}));
}));
})。然后(()=>clearMessages());
}

clearMessages();
这是因为下面提到的代码是未定义的

typeof document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token == undefined
只能对字符串数据类型使用替换函数


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

什么是
localStorage.token
?在理想情况下,
localStorage
中不存在此属性,因此您无法对其调用
replace
。请创建一个。这意味着
.contentWindow.localStorage.token
d不存在…!?