Unable to get mentioned user's role ID to determine next few lines of code

Yes, I am aware this looks strange I am relatively new to scripting and I am using a fairly strange warning system but hey, I didn’t choose the warning system, my clan leader did.

const Discord = require('discord.js');
const winston = require('winston');
const { prefix, token } = require('./auth.json');
const client = new Discord.Client();
const logger = winston.createLogger({
	transports: [
		new winston.transports.Console(),
		new winston.transports.File({ filename: 'log' }),
	format: winston.format.printf(log => `[${log.level.toUpperCase()}] - ${log.message}`),

client.on("ready", () => {
    client.user.setActivity("you.", { type: "WATCHING"})
    logger.log('info', 'Ready!');

client.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if (command === 'ping') {
    } else if (command === 'warn') {
	if (!message.member.permissions.has('ADMINISTRATOR')) {
	    return message.reply('You do not have the permission to do this!')
	} else {
	        if (!message.mentions.users.size) {
	            return message.reply('You failed to mention a user to warn!');
		const role1 = message.guild.roles.find("name", "Degree 1");
		const role2 = message.guild.roles.find("name", "Degree 2");
		const role3 = message.guild.roles.find("name", "Degree 3");
		const command2 = args.shift().toLowerCase();
	        const taggedUser = message.mentions.users.first();
		const taggedId = taggedUser.id;
		logger.log('debug', taggedUser.roles);
		if (command2 === taggedUser) {
		if(taggedId.roles.has(role3.id)) {

		    const roleNumber = 4
		} else if(taggedId.roles.has(role2.id)) {
		    const roleNumber = 3
		} else if(taggedId.roles.has(role1.id)) {
		    const roleNumber = 2
		} else {
		    const roleNumber = 1
		const command3 = args.shift();
		if (command3) {
		    return message.reply(`Giving ${taggedUser} a Degree for Reason: ${command3}.`);
		    client.channels.get("580595934262722565").send("`${taggedUser} = ${roleNumber} Degree(s)` \n `Reason: ${command3}`")
		} else {
		    client.channels.get("580595934262722565").send("`${taggedUser} = ${roleNumber} Degree(s)` \n `Reason: None`")
		    return message.reply(`Giving ${taggedUser} a Degree for no given reason.`);
    } else if (command === 'stop') {
	message.channel.send('Stopping...').then(() => {


That is the code and every time I run it I get an error reading:

PS C:\Users\Lenovo E531\Desktop\DiscordTimeBot> node bot.js
[INFO] - Ready!
C:\Users\Lenovo E531\Desktop\DiscordTimeBot\bot.js:42
                if(taggedId.roles.has(role3.id)) {

TypeError: Cannot read property 'has' of undefined
    at Client.client.on.message (C:\Users\Lenovo E531\Desktop\DiscordTimeBot\bot.js:42:21)
    at Client.emit (events.js:198:13)
    at MessageCreateHandler.handle (C:\Users\Lenovo E531\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Users\Lenovo E531\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Users\Lenovo E531\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\Lenovo E531\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\Lenovo E531\node_modules\discord.js\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:198:13)
    at Receiver.receiverOnMessage (C:\Users\Lenovo E531\node_modules\discord.js\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:198:13)

If anyone here can help and maybe even get this working I would appreciate it as my server uses a role warning system, 4 warns and you get kicked, and I am making this bot to help clean this up.

1 Like

Try changing this to:
if(taggedId.roles.get(role3.id)) {

Just a note your bot code/command is very overcomplicated. If you need help, don’t hesitate to message me or dm me on Discord…

1 Like

may I ask your discord? - also your solution did not work

Hey there,
You see users do not have the property role, rather members.

const member = message.mentions.members.first();
if (member.roles.has('Role ID')) {
    // code here
1 Like

Speedy#9365 if you wanna hit me up