Javascript “如何修复”;DiscordAPIError:未知通道“;关于那个密码?

Javascript “如何修复”;DiscordAPIError:未知通道“;关于那个密码?,javascript,discord.js,Javascript,Discord.js,我有这个代码,工作正常。 它用于在超时后删除空的语音频道,当有人加入时,它也会清除超时 client.once('ready',()=>{ var interval=setInterval(函数(){ const parent=client.channels.get(“469457677144293376”) parent.children.filter(cha=>cha.type===“voice”&&cha).forEach(cha=>{ 如果(cha.members.size==0){ 变

我有这个代码,工作正常。 它用于在超时后删除空的语音频道,当有人加入时,它也会清除超时

client.once('ready',()=>{
var interval=setInterval(函数(){
const parent=client.channels.get(“469457677144293376”)
parent.children.filter(cha=>cha.type===“voice”&&cha).forEach(cha=>{
如果(cha.members.size==0){
变量计时器=设置超时(()=>{
cha.删除()
}, 5000);
}
var interval=setInterval(函数(){
如果(cha.members.size!==0){
清除超时(计时器)
}
}, 1 * 500);
})
}, 1 * 500);
});
这是我在控制台上遇到的错误:

(node:8025) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Channel
    at item.request.gen.end (/rbd/pnpm-volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
    at then (/rbd/pnpm-volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/snekfetch/3.6.4/node_modules/snekfetch/src/index.js:215:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(node:8025) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:8025) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:8025) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Channel
    at item.request.gen.end (/rbd/pnpm-volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
    at then (/rbd/pnpm-volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/snekfetch/3.6.4/node_modules/snekfetch/src/index.js:215:21)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
(节点:8025)未处理的PromisejectionWarning:DiscordAPIError:未知通道
在item.request.gen.end(/rbd/pnpm volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
当时(/rbd/pnpm volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/snekfetch/3.6.4/node_modules/snekfetch/src/index.js:215:21)
在
在进程中。_tick回调(内部/process/next_tick.js:189:7)
(节点:8025)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:2)
(节点:8025)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。
(节点:8025)未经处理的PromisejectionWarning:DiscordAPIError:未知通道
在item.request.gen.end(/rbd/pnpm volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/discord.js/11.5.1/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15)
当时(/rbd/pnpm volume/9841fb11-337a-4c3b-bf2e-08d60ed04d96/node_modules/.registry.npmjs.org/snekfetch/3.6.4/node_modules/snekfetch/src/index.js:215:21)
在
在进程中。_tick回调(内部/process/next_tick.js:189:7)
我尝试了返回、过滤、捕获,但什么都没有:/


有什么想法吗?和thx:)

每半秒,您的代码就会循环通过每个频道,这些频道既是定义类别的子频道,也是语音频道。您设置了5秒的超时以删除频道。但是,下次间隔滴答作响时,它会再次设置相同的超时,因为通道仍然存在。当重复超时尝试删除曾经存在的通道时,会抛出错误,因为第一个超时删除了该通道

使用此代码,将实现一个队列,并且仅将不在队列中的通道设置为删除。如果通道不是空的,它将从队列中删除,超时不会删除它。这样,在下一个滴答声中,通道将再次排队。如果通道确实为空,它将在5秒内被删除,然后从队列中删除。如果通道不再存在,代码将不会尝试删除它,而是将其从队列中删除。最后,当不再存在语音通道时,间隔将被清除

client.once('ready',()=>{
常量队列=[];
常量间隔=设置间隔(()=>{
const parent=client.channels.get('469457677144293376');
如果(!父项){
console.error('缺少父通道');
返回clearInterval(间隔);
}
const voiceChildren=parent.children.filter(channel=>channel.type=='voice');
如果(voiceChildren.size==0){
console.log('删除所有语音频道');
返回clearInterval(间隔);
}
voiceChildren.filter(channel=>!queue.includes(channel.id)).forEach(channel=>{
queue.push(channel.id);
设置超时(()=>{
if(!client.channels.get(channel.id)){
console.log(`${channel.name}已被删除;正在中止。`);
返回queue.splice(queue.indexOf(channel.id),1);
}
如果(channel.members.size!==0){
console.log(`${channel.name}不为空;请重试。`);
返回queue.splice(queue.indexOf(channel.id),1);
}
channel.delete()
.then(()=>queue.splice(queue.indexOf(channel.id),1))
.catch(控制台错误);
}, 5000);
});
}, 500);
});

每半秒钟,您的代码就会循环通过每个频道,这些频道既是定义类别的子频道,也是语音频道。您设置了5秒的超时以删除频道。但是,下次间隔滴答作响时,它会再次设置相同的超时,因为通道仍然存在。当重复超时尝试删除曾经存在的通道时,会抛出错误,因为第一个超时删除了该通道

使用此代码,将实现一个队列,并且仅将不在队列中的通道设置为删除。如果通道不是空的,它将从队列中删除,超时不会删除它。这样,在下一个滴答声中,通道将再次排队。如果通道确实为空,它将在5秒内被删除,然后从队列中删除。如果通道不再存在,代码将不会尝试删除它,而是将其从队列中删除。最后,当不再存在语音通道时,间隔将被清除

client.once('ready',()=>{
常量队列=[];
常量间隔=设置间隔(()=>{
const parent=client.channels.get('469457677144293376');
如果(!父项){
console.error('缺少父通道');
返回clearInterval(间隔);
}
const voiceChildren=parent.children.filter(channel=>channel.type=='voice');
如果(voiceChildren.size==0){
console.log('所有voic