Discord.js sending user-programmed private messages with a scroll

Asked

Viewed 4,776 times

0

Hello

I don’t know if anyone is aware of Discord.js but I’ll ask anyway

I am making a small student guide, IE, something that can warn the student of what is happening in their school life

What I’m trying to do is not send programmed private messages since I use Node.Chedule to do so, but send them to people with a specific role

    const botconfig = require('./botconfig.json');
const token = '*';
const Discord = require('discord.js');
const schedule = require('node-schedule');
const client = new Discord.Client();
var classA = '?';
var sumaryA = '?';
var profA = '?';

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



  var class8_30 = schedule.scheduleJob({hour: 8, minute: 30, dayOfWeek: 1}, function(){
    classA = 'English'; 
    client.users.get("500087456046120961").send("Class now");
  });

});

client.on('message', msg => {

  if (msg.content === 'ping') {
    msg.reply('pong');
  }

  if(msg.content.toLowerCase().startsWith('!myclassis')){
    var args = msg.content.toLowerCase().split(' ');
    console.log(args);
    if(args[1] === '10a'){
      var t10A = msg.guild.roles.find('name', 'Class_10A');
      msg.member.addRole(t10A.id);
      msg.channel.send('You\'re now part of class 10A');
    }
  }

  if (msg.content.toLowerCase() === "class"){
    let c10A = msg.guild.roles.find("name", "Class_10A");
    if (msg.member.roles.has(c10A.id)) 
        msg.author.send(aulaA);
  }

});

client.login(token);

The way I have now is to send a message by id what is enough (in)practical and it is not automatic, I have seen a huge amount of videos, I have already read the videos but I can not find anywhere but I think there is

If anyone could help me I would appreciate the help and time spent with this problem of mine :)

Note: Apologies for the lack of accents, English keyboard in English linux :/ Note 2: Discord.js does not have enough reputation in the tags so I put in the title

1 answer

0

From what I understand, you want to rescue all users from a specific server job instead of releasing multiple client.users.get().send() for each user. You can recover these users using client.guilds.get().roles.get().members:

client.guilds.get("ID do servidor").roles.get("ID da role").members.forEach((membro) => {
    membro.user.send("Class now")
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.