discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.23k stars 3.96k forks source link

Discord.js - .addRole is not a function #2980

Closed SleepingCiaran closed 5 years ago

SleepingCiaran commented 5 years ago

Hello, I am creating a Discord Bot and I am trying to make an Mute Command, but I always get the same error.

image

Can you guys help me?

Some information:

Code:

const { Command } = require('klasa');
const { MessageEmbed } = require('discord.js');

module.exports = class extends Command {

    constructor(...args) {
        super(...args, { description: 'Mute an user.' })
    }

    async run(msg, args) {
        if(!msg.member.hasPermission("MANAGE_MEMBERS")) return msg.channel.send("You can't use this command.");

        let MuteUser = msg.guild.member(msg.mentions.users.first() || msg.guild.members.get(args[0]))
        if(!MuteUser) return msg.channel.send("Can't find user!");

        let MuteReason = msg.content.split(" ").slice(2).join(" ");

        let MuteRole = msg.guild.roles.find(r => r.name === "Spammer");
        if(!MuteRole) return msg.channel.send("Can't find the Spammer role!");

        let MuteChannel = msg.guild.channels.find(guild => guild.name === 'bot-logs');
        if(!MuteChannel) return msg.channel.send("Can't find the #bot-logs channel.");

        if(MuteUser.roles.has(MuteRole)) return msg.channel.send("That user is already muted!.");

        MuteUser.addRole(MuteRole.id);

        return MuteChannel.send(new MessageEmbed()
            .setAuthor("Mute"|| 'Unknown', "http://wolfdevelopment.cf/BotSymbols/info.png")
            .setColor("#ff0000")
            .addField("Muted User", `${MuteUser}`)
            .addField("Muted By", `<@${msg.author.id}>`)
            .addField("Muted In", `${msg.channel}`)
            .addField("Time", `${msg.createdAt}`)
            .addField("Reason", `${MuteReason}`));
    }
}
kyranet commented 5 years ago

This is more a klasa question than a discord.js, this issue does not belong here but in Dirigeants Headquarter's support. There's an invite button in the official page, top right, see you there!