Discord.js sending a message to a specific channel

You didn't provide any code that you already tested so I will give you the code for your ready event that will work!

    client.on('ready', client => {
        client.channels.get('CHANNEL ID').send('Hello here!');
    })

Be careful that your channel id a string.

Let me know if it worked, thank you!

2020 Jun 13 Edit:

A Discord.js update requires the cache member of channels before the get method.

If your modules are legacy the above would still work. My recent solution works changing the send line as follows.

        client.channels.cache.get('CHANNEL ID').send('Hello here!')

If you are using TypeScript, you will need to cast the channel in order to use the TextChannel.send(message) method without compiler errors.

import { TextChannel } from 'discord.js';

( client.channels.cache.get('CHANNEL ID') as TextChannel ).send('Hello here!')

This will work for the newest version of node.js msg.guild.channels.cache.find(i => i.name === 'announcements').send(annEmbed)


for v12 it would be the following:

  client.on('messageCreate', message => {
        client.channels.cache.get('CHANNEL ID').send('Hello here!');
    })

edit: I changed it to log a message.


This should work

client.channels.fetch('CHANNEL_ID')
    .then(channel=>channel.send('booyah!'))