I want my bot to send a message to a certain channel in my discord server.
So I would like to run a command like -announce [my message here]
and it would send it to a channel in my server called Announcements
.
I have already tried something like this return message.channels.get("336313710106902529").send(announceembed)
but it just gives me an error in my console.
` 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)
}
`
My expected result is for my bot to send a message to the announce channel. Except it gives me the following error:
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.```