0

im still fairly new to javascript but im currently trying to make a cron message , it does work but now im trying to figure out how to send it to a specific channel

this is what i have so far

var CronJob = require('cron').CronJob;
var job = new CronJob('1 * * * * *', function () {
    message.channel.send('You will see this message every second');
}, null, true, 'America/Los_Angeles');
job.start(); 

i have tried a few things but it either doesnt work or causes the code to crash

2 Answers2

0

You can define a channel by finding one by name or id.

Find one by ID:

client.channels.cache.find(c => c.id === "id");

Find one by name:

client.channels.cache.find(c => c.name === "name")
Marino
  • 3
  • 4
0

Marino's answer is technically correct but it's not what is recommended. You should do:

<client>.channels.cache.get("ID HERE")

or

<client>.channels.cache.find(c => c.name === "name")

it's best to use .get for IDs.

Furthermore, your bot could get ratelimited if you send a message every second.

iTrxpical
  • 101
  • 10