Reputation: 49
My bot is going to send a private message to a list of people who are accepted.
I want to type in a command that sends a message to everyone in the .json
file.
I have tried with a loop, but can't get it to work.
I am thinking of this to be the json file:
{
"1": "Name#0001",
"2": "Guy#0001",
"3": "Person#0001"
}
This is my index.js or main.js:
var ytLinks = JSON.parse(fs.readFileSync('./ytvids.json', 'utf8'));
if (args[1] === 'send') {
const userValues = Object.values(acceptedUsers);
var userList = '';
var i;
for (i = 0; i < userValues.length; i++) {
userList += userValues[i];
}
}
Upvotes: 4
Views: 134
Reputation: 8412
{
"1": "Name#0001",
"2": "Guy#0001",
"3": "Person#0001"
}
const obj = require('./something.json') // require object from file
// execute function on each entry (user tag)
Object.values(obj).forEach((tag) => {
// find each user via tag and send DM
client.users.cache.find(user => user.tag === tag).send('This is a DM')
});
Be careful, too much mass DMing can lead to problems with Discord's Terms of Service
Upvotes: 4