Wyślij prywatną wiadomość do listy osób

Aug 16 2020

Mój bot wyśle ​​prywatną wiadomość do listy zaakceptowanych osób. Chcę wpisać polecenie, które wyśle ​​wiadomość do wszystkich w .jsonpliku. Próbowałem z pętlą, ale nie mogę jej uruchomić.

Myślę o tym jako o pliku json:

{
    "1": "Name#0001",
    "2": "Guy#0001",
    "3": "Person#0001"
}

To jest mój index.js lub 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];
  }
}

Odpowiedzi

4 Lioness100 Aug 16 2020 at 20:08

coś.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() metoda
  • Array.prototype.forEach() metoda
  • Array.prototype.find() metoda

Uważaj, zbyt masowe DMing może prowadzić do problemów z Warunkami korzystania z Discord