L
L
Limonic2021-03-14 20:41:39
Node.js
Limonic, 2021-03-14 20:41:39

The bot does not issue a role, I can not understand why?

Wrote a bot for issuing a role by reaction. The message is displayed, the reactions too, but the role is not issued. Help.

const config = require('./config.json'); 
const Discord = require('discord.js'); 
const client = new Discord.Client({ partials: ['message', 'channel', 'reaction'] });
const prefix = config.prefix; 
var emojiname = ["1️⃣"],
    rolename = ["817391471765356554"];

    client.on("ready", () => {
      console.log(`Logged in as ${client.user.tag}`)
  });
  client.on("message", e => {
    if (e.content.startsWith(prefix + "1️⃣")) {
        if (!e.channel.guild) return;
        for (let o in emojiname) {
            var n = [e.guild.emojis.find(e => e.name == emojiname[o])];
            for (let o in n) e.react(n[o])
        }
    }
});

    function role(robot, message, args) {
if (message.content === `?role`) 
 message.channel.send('Чтобы выбрать роль, нажмите на реакцию под сообщением. 1️⃣ , если вы учитесь на первом курсе. 2️⃣ если вы учитесь на втором курсе. 3️⃣ если вы учитесь на третьем курсе. 4️⃣ если вы учитесь на четвёртом курсе.').then (sentMessage => {
 sentMessage.react(`1️⃣`)
 sentMessage.react(`2️⃣`)
 sentMessage.react(`3️⃣`)
 sentMessage.react(`4️⃣`)
})
}
client.on("messageReactionAdd", (e, n) => {
  if (n && !n.bot && e.message.channel.guild)
    for (let o in emojiname)
    {
        if (e.emoji.name == o) {
            e.message.member.roles.add('817391471765356554');
        }
    } 
});
client.on("message", e => {
  if (e.content.startsWith(prefix + "1️⃣")) {
      if (!e.channel.guild) return;
      for (let o in emojiname) {
          var n = [e.guild.emojis.find(e => e.name == emojiname[o])];
          for (let o in n) e.react(n[o])
      }
  }
});
client.on("messageReactionRemove", (e) => {
  if (n && !n.bot && e.message.channel.guild)
      for (let o in emojiname)
        {
          if (emojiname == o) {
              e.message.member.roles.remove('&817391471765356554')
          }
        }
});
    

var comms_list = [{
  name: "role",
  out: role,
  about: "выдача роли"
}];

module.exports.comms = comms_list;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question