首页 > 解决方案 > 如何修复 UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Channel

问题描述

我只会读这个频道,但它出错(节点:17212)UnhandledPromiseRejectionWarning:DiscordAPIError:未知频道

我的代码

client.on('message', async message => {
  if(message.channel.name.includes("Command-only")){
    message.channel.bulkDelete("1", true);
    if(!message.author.bot){
message.channel.send("Test, you say :" + `${message.content}`);
}
}
})

标签: discord.js

解决方案


您的机器人正在阅读所有发送给它的消息,包括没有名称的 DM。您应该过滤掉 dm 频道。

if(message.channel.type === 'dm') return;

推荐阅读