Invia messaggio privato a un elenco di persone
Aug 16 2020
Il mio bot invierà un messaggio privato a un elenco di persone accettate. Voglio digitare un comando che invia un messaggio a tutti nel .json
file. Ho provato con un ciclo, ma non riesco a farlo funzionare.
Sto pensando che questo sia il file json:
{
"1": "Name#0001",
"2": "Guy#0001",
"3": "Person#0001"
}
Questo è il mio index.js o 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];
}
}
Risposte
4 Lioness100 Aug 16 2020 at 20:08
something.json:
{
"1": "Name#0001",
"2": "Guy#0001",
"3": "Person#0001"
}
index.js:
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')
});
- Object.values() metodo
- Array.prototype.forEach() metodo
- Array.prototype.find() metodo
Fai attenzione, troppi messaggi di massa possono portare a problemi con i Termini di servizio di Discord