I have two text files, one with discord usernames with #, and another with the same amount of unique urls. I'm trying to make a discord bot to send each person one of the unique urls. I have run into an issue trying to send a test dm to one person. I keep getting the error.
TypeError: Cannot read property 'send' of undefined
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready');
client.users.cache.get('877248726085828720').send('yo');
});
// Login to Discord with your client's token
client.login(token);
Soo at the begining I think that you lose one intend so search them in API Documentation Discord.js Second I don't really understand where yiu want to send message but it should look like this
client.channels.cache.get('idhere').send('message');
I hope that helps you. Give me feedback if it does.
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.