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
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'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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.