Skip to content
Advertisement

Why does my addrole command have errors? (discord.jsV12)

So basically my addrole command after the new version of discord.jsv13 no longer works and displays errors like role.id is not a function or role.id is not defined even though I believe there is no error, I’m pretty experienced with javascript but I tried different methods of fixing it but neither seem to do the trick, maybe because v12 is deprecated the discord API malfunctions idk?

The code

const lineReplyNoMention = require('discord-reply');
const color = process.env.Color;
module.exports = {
    name: 'addrole',
    cooldown: 5,
    aliases: ['addnewrole'],
    permissions: ["MANAGE_ROLES"],
    clientpermissions: ["MANAGE_ROLES", "SEND_MESSAGES", "EMBED_LINKS"],
    async execute(client, message, cmd, args, Discord) {
        const user = message.mentions.users.first();
        const usertarget = message.guilds.members.cache.get(user.id);
        if (!user) {
            const nopr = new Discord.MessageEmbed().setTimestamp().setColor(`${color}`).setAuthor(`${message.author.username}`, message.author.displayAvatarURL({ dynamic: true })).setDescription(`**`(prefix)addrole <@user> <@role>`**`)
            return message.lineReplyNoMention({ embed: nopr })
        }
        args.shift()
        const roleToGive = message.mentions.roles.first()
        if (!roleToGive) {
            const addroleError2 = new Discord.MessageEmbed().setTimestamp().setDescription(`**No Roles Provided!**`).setColor(`${color}`)
            return message.lineReplyNoMention({ embed: addroleError2 })
        }
        usertarget.roles.add(roleToGive.id)
        const embed = new Discord.MessageEmbed().setTimestamp().setColor(`${color}`).setAuthor(`${message.author.username}`, message.author.displayAvatarURL({ dynamic: true })).setDescription(`**Added: `${roleToGive}` To `${user.username}`**`)
        message.lineReplyNoMention({ embed: embed })
    }
}

Advertisement

Answer

I think your issue may come from your discord-reply npm package which isn’t updated.

I took the time to edit your code and fix some issues I found. The code below worked on my side.

//Import MessageEmbed class for the embeds.
const { MessageEmbed } = require("discord.js");
const color = process.env.Color;
module.exports = {
    name: 'addrole',
    cooldown: 5,
    aliases: ['addnewrole'],
    permissions: ["MANAGE_ROLES"],
    clientpermissions: ["MANAGE_ROLES", "SEND_MESSAGES", "EMBED_LINKS"],
    async execute(client, message, cmd, args, Discord) {
        const user = message.mentions.users.first();
        const usertarget = message.guild.members.cache.get(message.author.id); //guilds to guild & user to message.author
        if (!user) {
            const nopr = new MessageEmbed().setTimestamp().setColor(`${color}`).setAuthor(`${message.author.username}`, message.author.displayAvatarURL({ dynamic: true })).setDescription(`**`(prefix)addrole <@user> <@role>`**`)
            return message.reply({ embeds: [nopr] }) //reply instead
        }
        args.shift()
        const roleToGive = message.mentions.roles.first()
        if (!roleToGive) {
            const addroleError2 = new MessageEmbed().setTimestamp().setDescription(`**No Roles Provided!**`).setColor(`${color}`)
            return message.reply({ embeds: [addroleError2] }) //reply instead.
        }
        usertarget.roles.add(roleToGive.id)
        const embed = new MessageEmbed().setTimestamp().setColor(`${color}`).setAuthor(`${message.author.username}`, message.author.displayAvatarURL({ dynamic: true })).setDescription(`**Added: `${roleToGive}` To `${user.username}`**`)
        message.reply({ embeds:  }) //reply instead.
    }
}
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement