我想让我的机器人发送一个消息到我的discord服务器中的某个频道。
所以我想运行一个类似-announce[my message here]
的命令,它会将它发送到我的服务器中名为announcements
的通道。
我已经尝试了类似于return message.channels.get(“336313710106902529”)。send(announceembed)
的操作,但它只是在控制台中给我一个错误。
`const msg=message.content const announcechannel=bot.channels.get(“336313710106902529”);
if(cmd === `${prefix}announce`){
let announceembed = new Discord.RichEmbed()
.setTitle(":flag_jp: **Announcement** :flag_jp:")
.setDescription(msg)
.setColor("#ff0000");
return message.channels.get("336313710106902529").send(announceembed)
}
“
我的预期结果是我的机器人向公告通道发送一条消息。但它会给我以下错误:
at Client.bot.on (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\index.js:65:33)
at Client.emit (events.js:189:13)
at MessageCreateHandler.handle (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver._receiver.onmessage (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\ws\lib\websocket.js:137:47)
at Receiver.dataMessage (C:\Users\craig\OneDrive\Documents\Visual Studio Code\bot\node_modules\ws\lib\receiver.js:409:14)
(node:896) 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:896) [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.```
没有channels
属性,只有channels
,它是消息来自的通道。
您要查找的是
:
const msg = message.content;
const announceChannel = bot.channels.get("336313710106902529");
if(cmd === `${prefix}announce`){
let announceEmbed = new Discord.RichEmbed()
.setTitle(":flag_jp: **Announcement** :flag_jp:")
.setDescription(msg)
.setColor("#ff0000");
return announceChannel.send(announceEmbed);
}