简体   繁体   中英

How to have discord.js send a dm to someone

I want it to send at a specific time. I have that part worked out with cron. I dont know how create a function that actually sends the message from the bot.

const Discord = require('discord.js');
const client = new Discord.Client();
var cron = require("cron");

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

let scheduledMessage = new cron.CronJob("30 52  20 * * *", () => {
  client.users.get('ID').send('test');
})
scheduledMessage.start();

client.login(token);

This should work for some people if using v11.


If you are using v12:

  1. Use client.users.cache.get
  2. If it still doesn't work you need to use fetch .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM