Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send a message to a specific channel

I'm trying to send a message to a specific channel with my Discord bot, which is in several servers. I want the bot to pick up on a message from one server and send a message to my personal server, in a specific channel, but I can't get it to 'find' the channel. Has the API changed or something? I tried npm install discord.js to update too.

Code:

if (message.author.id == 'XXXXX' && !mess.includes("Dank") && message.channel.id != 'XXXXX') {
  bot.channels.get('XXXXX').send('memes');
}

I tried a few things but none worked.

TypeError: Cannot read property 'send' of undefined
    at decideIfMention (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\bot.js:80:45)
    at Client.bot.on (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\bot.js:68:3)
    at emitOne (events.js:116:13)
    at Client.emit (events.js:211:7)
    at MessageCreateHandler.handle (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\XXXX\Desktop\Coding Crud\Discord Bot 2\node_modules\ws\lib\event-target.js:120:16)
    at emitOne (events.js:116:13)
like image 306
aandamitchell Avatar asked Jul 01 '18 02:07

aandamitchell


People also ask

How do you make a Discord BOT send a message at a certain time?

To set a timed message, open MEE6 dashboard and open the server that you want to send the message to. Here scroll down and select the Timers option. On the Timers page, click on Add Timer button and select the channel, time and enter the message that Mee 6 has to send. Once done, click on Create.


1 Answers

Well, if you have the "client" instance of Discord.Client(), then use this:

SOLUTION UPDATED to work with newer discordjs versions

client.channels.cache.get(`channelID`).send(`Text`)

Don't forget the channeID parameter is a string type, not number. It's really simple yet precise.

like image 103
The Real Underscore Avatar answered Sep 18 '22 16:09

The Real Underscore