D
D
Dmitry Belich2021-07-16 06:40:44
Node.js
Dmitry Belich, 2021-07-16 06:40:44

How to give a role in a discord.js bot? How to issue a role knowing only role id and member id? And not having a message?

There is this code:

let timerId = setInterval(function tick() {
  fs.readFile('doebator.json', (err, data) => {
    if (err){
        // Обработка ошибок
        return console.log(err);
    }

    var userData = JSON.parse(data);
    var d = new Date,
    dformat = [d.getDate(),
      d.getMonth()+1,
      d.getFullYear()].join('.')+'-'+
      [d.getHours(),
      d.getMinutes()].join('.');
      if(userData.length != null){
      if(dformat>=userData[0].time){
   // robot.channels.cache.get(userData[0].channel).send(`<@${userData[0].user}> вы размучены`)
    userData.splice(0);
    }
  }
});
}, 5000);

How do I know the user id, delete and add a role to him?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-07-16
@Dmitrium12

you need to have at least the ID of the server on which you want to give the user a role.
based

// robot.channels.cache.get(userData[0].channel).send(`<@${userData[0].user}> вы размучены`)

...I can offer the following option, where the bot, knowing the channel ID, gets the server ID:
/* для добавления роли */

robot.guilds.cache.get(robot.channels.cache.get(userData[0].channel).guild.id).members.cache.get("id_пользователя").roles.add("id_роли")

/* для удаления роли*/

robot.guilds.cache.get(robot.channels.cache.get(userData[0].channel).guild.id).members.cache.get("id_пользователя").roles.remove("id_роли")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question