【发布时间】:2020-10-11 19:57:58
【问题描述】:
所以基本上我正在尝试使用message.mentions.channels向特定频道发送通知
前!announce #announcements Today is a great day!
错误:
(node:5516) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'channels' of undefined
at Object.module.exports.execute (C:\Users\Zarko\Desktop\Stackoverflow\commands\Answers\announce.js:3:36)
at Client.<anonymous> (C:\Users\Zarko\Desktop\Stackoverflow\events\message.js:20:30)
at Client.emit (events.js:223:5)
at MessageCreateAction.handle (C:\Users\Zarko\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\Zarko\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\Zarko\node_modules\discord.js\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:223:5)
(node:5516) 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: 1)
(node:5516) [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.
代码:
let channel = message.mentions.channels.first();
if (!channel) return
let announcement = args.slice(1).join(" ");
channel.send(announcement)
【问题讨论】:
-
报错说它无法访问undefined的属性channel,你提供的代码中没有你尝试访问“.channel”的地方,所以我们需要更多的代码
-
这就是我的全部
-
@Karizma 有解决方案吗?
-
这不可能是所有代码,除非您输入错误。它应该告诉您行号,因此添加该行和该行的相关周围代码。
-
没关系,它现在可以工作,什么也没做,它可以工作,无论如何感谢您的帮助
标签: bots discord discord.js