Discord.js Error: addRole is not a function

Discord.js Error: addRole is not a function

我遇到一个非常奇怪的错误,当我转到 运行 我的 Discord Bot 时,控制台输出 yeet.addRole(Punished) is not a function 的错误。我不明白为什么,因为我在代码的开头使用了 addRole() 并且那个似乎有效。谁能告诉我为什么会这样???错误发生在从底部算起的第 9 行。

    const Discord = require("discord.js");
const bot = new Discord.Client();
const prefix = "/"
const version = "3.2.4"
const token = "sometoken"
const game = "with you!"
const status = "Online"

//embedColors

const embedRed = 0xff0000
const embedOrange = 0xff790c
const embedYellow = 0xffff00
const embedGreen = 0x00ff00
const embedBlue = 0x0064ff
const embedPurple = 0x6a00b0
const embedMagenta = 0x9600ff
const embedPink = 0xff00ff
const embedBlack = 0x000000
const embedWhite = 0xffffff
const embedGray = 0x777777

var x = [
    1,
    2,
    3,
    4,
    5,
]

var output = x[Math.floor(Math.random()*x.length)];


var fortunes = [
    "Yes.",
    "It is certain.",
    "It is decidedly so.",
    "Without a doubt.",
    "Yes definelty.",
    "You may rely on it.",
    "As I see it, yes.",
    "Most likely.",
    "Outlook good.",
    "Signs point to yes.",
    "Reply hazy, try again.",
    "Ask again later.",
    "Better not tell you now...",
    "Cannot predict now.",
    "Concentrate and ask again.",
    "Don't count on it.",
    "My reply is no.",
    "My sources say no.",
    "Outlook not so good...",
    "Very doubtful.",
];

//bot ready
bot.on("ready", () => {
    bot.user.setStatus(status)
    bot.user.setGame(game)
    console.log("Bot Ready For Use")
})

//swear detector

/*bot.on('message', message => {
    let user = message.author;
    let modlog = bot.channels.find("name", "mod-log");
    let reason = "No Swearing";


    if (message.content.toLowerCase().includes("fuck") || message.content.toLowerCase().includes("bitch") || message.content.toLowerCase().includes("ass") || message.content.toLowerCase().includes("shit") || message.content.toLowerCase().includes("penis") || message.content.toLowerCase().includes("pussy") || message.content.toLowerCase().includes("vagina") || message.content.toLowerCase().includes("sex")){
    message.guild.member(user).kick(reason + `\n ***You can rejoin by joining Error 316; Too MLG, clicking on the __#partners__ text channel, and selecting your server from the list.***`);
    const kembed = new Discord.RichEmbed()
        .setAuthor(`${user.username} has been kicked from the server.`, user.displayAvatarURL)
        .addField("Kick information", `**Kicked User:** ${user.tag}\n**Moderator:** ${message.author.tag}\n**Reason:** ${reason}`)
        .setColor(embedRed);
    modlog.send({
    embed : kembed
    })}
    else{}
});*/

//basic

bot.on("message", message => {

    if (message.content == "Who's Overseer?"){
        //message.reply("pong")
        message.channel.sendMessage("Well I'm a bot created by Server Owner, 316thebrains for the purpose of watching over his server whenever he goes AFK. So dont get any ideas.")
    }
    else if (message.content.toLowerCase() == "i hate you overseer"){
        message.channel.sendMessage(`Awwww, Thanks ${message.author}`)
    }
    else if (message.content == "Is there anybody online?".toLowerCase() || message.content == "Is there anybody online?" || message.content == "Is anybody online?".toLowerCase() || message.content == "Is anybody online".toLowerCase()){
        message.channel.sendMessage("I'm online!")
    } 
    else if (message.content == "Hey Overseer!" || message.content == "hey Overseer!" || message.content == "hey overseer!" || message.content == "Hey Overseer" || message.content == "hey Overseer" || message.content == "hey overseer"){
        message.channel.sendMessage("Whats Up?")
    }
    else if (message.content == "Where is 316thebrains" || message.content == "Where are the admins" || message.content == "Where is 316thebrains".toLowerCase || message.content == "Where are the admins".toLowerCase || message.content == "Where is 316thebrains?" || message.content == "Where are the admins?" || message.content == "Where is 316thebrains?".toLowerCase || message.content == "Where are the admins?".toLowerCase){
        message.channel.sendMessage("I'm not sure, but if you have any issues with players im here!")
    }
    else if (message.content == "bots.access.overseer.launchProtocal:316,modifiers='12,5,53,30'"){
        for (i = 0; i < 30; i++) {
            message.channel.sendMessage("SPAM_SPAM_SPAM_SPAM_SPAM_SPAM_SPAM_SPAM")
    }}
    else if (message.content == "Good one Overseer!"){
        message.channel.sendMessage("Thank you, " + message.author)
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content.toLowerCase() == "hey overseer, send a default_embed"){
        message.channel.sendMessage("This is an example of an embed.")
        message.channel.send({embed: {
            color: 0xf50107,
            title: `${bot.user.displayAvatarURL} This is an embed.`,
            description:`Bots use this to display messages seperately from user messages/mentions.`
            }});
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content == `bots.access.overseer.makeUser:ADMIN;bots.access.overseer.showCommands("ALL")`){
        message.author.sendMessage("bots.access.overseer.launchProtocal:316,modifiers='12,5,53,30' will spam a server.");
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content == `bots.access.overseer.force_kick:user=`){
        if(!message.guild.member(bot.user).hasPermission("KICK_MEMBERS")) return console.log(`force_ban by ${message.author} failed. Insufficient permissions.`)
        let usery = message.mentions.user.first();
        let reasony = "Force Banned by an **ADMIN** for __innappropriate__ *and/or* __offensive__ content"
        let generaly = bot.channels.find("name", "general");

        message.guild.member(usery).kick(reason);

        const ybanembed = new Discord.RichEmbed()
        .setAuthor(`${usery.username} has been __**FORCE KICKED**__ from the server.`, usery.displayAvatarURL)
        .addField("Kick information", `**Kicked User:** ${user.tag}\n**Reason:** ${reasony}`)
        .setColor(embedRed);
        general.send({
        embed : ybanembed
        });
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content == `bots.access.overseer.force_ban:user=`){
        if(!message.guild.member(bot.user).hasPermission("BAN_MEMBERS")) return console.log(`force_ban by ${message.author} failed. Insufficient permissions.`)
        let userX = message.mentions.user.first();
        let reasonX = "Force Banned by an **ADMIN** for __innappropriate__ *and/or* __offensive__ content"
        let general = bot.channels.find("name", "general");

        message.guild.member(userX).ban(reason);

        const Fbanembed = new Discord.RichEmbed()
        .setAuthor(`${userX.username} has been __**FORCE BANNED**__ from the server.`, userX.displayAvatarURL)
        .addField("Kick information", `**Banned User:** ${user.tag}\n**Reason:** ${reason}`)
        .setColor(embedRed);
        general.send({
        embed : Fbanembed
        });
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content == `bots.access.overseer.say:msg=`){
        let wurdz =  message.content.slice("bots.access.overseer.say:msg=".length);

        message.channel.send(wurdz)
        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
    else if (message.content.includes == `bots.access.overseer.forceRank=`){
        let rank = message.mentions.roles.first();
        let role = member.guild.roles.find(`name`, `${rank}`);
        message.author.addRole(role);

        setTimeout( () => {
            message.channel.bulkDelete(2);;
        }, 500);
    }
});

//new member

bot.on('guildMemberAdd', member => {
    // Send the message to a designated channel on a server:
    let modlog = 
    console.log(` >>User ${member.user.username} has joined.`);
/////////////////////////////////////////////////////////////////////////////

    const Member = member.guild.roles.find(`name`, `Member`)
    const Noob = member.guild.roles.find(`name`, `Noob`)
    member.addRole(Member);
    member.addRole(Noob);
});
//commands

bot.on("message", function(message) {
    if (message.author.equals(bot.user)) return;

    if (!message.content.startsWith(prefix)) return;

    var args = message.content.substring(prefix.length).split(" ");

    switch (args[0].toLowerCase()) {
        case "ping":
            message.channel.send({embed: {
            color: embedRed,
            title: "Pong!",
            }});
            break;

        case "info":
            message.channel.send({embed: {
            color: 0xf50107,
            title: "Currently using latest version of Overseer.",
            description: "(Version " + version + ")",
            }});
            break;

        case "8ball":
            if (args[1]) {
                //message.channel.sendMessage(fortunes[Math.floor(Math.random() * fortunes.length)]);
                message.channel.send({embed: {
                    color: embedRed,
                    title: "Hmmm...",
                    description: (fortunes[Math.floor(Math.random() * fortunes.length)]),
                    }});
            }
            else {
                message.channel.send({embed: {
                    color: embedRed,
                    title: "Oops...",
                    description: "The usage of this command is: **/8ball [Question]**",
                    }});
            }
            break;

        case "roll":
        message.channel.send({embed: {
                    color: embedRed,
                    title: "You rolled...",
                    description: Math.floor(Math.random() * 6) + 1,
                    }});
                    break;

        case "admin":
            message.reply("Nice try, but no.");
            break;  

        case "kick":
            if(!message.guild.member(message.author).hasPermission("KICK_MEMBERS")) return message.reply("It appears you don't have permission to do this.")
            if(!message.guild.member(bot.user).hasPermission("KICK_MEMBERS")) return message.reply("It appears I don't have permission to do this.")

            let user = message.mentions.users.first();
            let reason = message.content.split(" ").slice(2).join(" ");
            let modlog = bot.channels.find("name", "mod-log");

            if(!modlog) return message.reply("I've detected that this server doesn't have a mod-log channel.");
            if(message.mentions.users.size < 1) return message.reply("You must mention someone in order to kick them!");
            if(!reason) return message.reply("Enter a reason for kick.");
            if(!message.guild.member(user).kickable) return message.reply("I can't kick the owner!");

            message.guild.member(user).kick(reason + `You can re-join by going to Error 316; Too MLG by going to https://discordapp.com/invite/ArsJtNd, and then click on the "#partnerships" chat`);

            const kickembed = new Discord.RichEmbed()
            .setAuthor(`${user.username} has been kicked from the server.`, user.displayAvatarURL)
            .addField("Kick information", `**Kicked User:** ${user.tag}\n**Moderator:** ${message.author.tag}\n**Reason:** ${reason}`)
            .setColor(embedRed);
            modlog.send({
            embed : kickembed
            });
            break;

        case "ban":
            if(!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) return message.reply("It appears you don't have permission to do this.")
            if(!message.guild.member(bot.user).hasPermission("BAN_MEMBERS")) return message.reply("It appears I don't have permission to do this.")

            let user1 = message.mentions.users.first();
            let reason1 = message.content.split(" ").slice(2).join(" ");
            let modlog1 = bot.channels.find("name", "mod-log" || "moderation-log");

            if(!modlog1) return message.reply("I've detected that this server doesn't have a mod-log channel.");
            if(message.mentions.users.size < 1) return message.reply("You must mention someone in order to ban them!");
            if(!reason1) return message.reply("Enter a reason for ban.");
            if(!message.guild.member(user1).kickable) return message.reply("I can't ban the owner!");

            message.guild.member(user1).ban(reason);


            break;

        case "copycat":
            if(!message.guild.member(message.author).hasPermission("CHANGE_NICKNAME")) return message.reply("It appears you don't have permission to do this.")
            if(!message.guild.member(bot.user).hasPermission("CHANGE_NICKNAME")) return message.reply("It appears I don't have permission to do this.")

            message.guild.member(bot.user).setNickname('316thebrains');
            bot.user.setAvatar("316thebrains.jpg");
            break;

        case "copycat_clear":
            if(!message.guild.member(message.author).hasPermission("CHANGE_NICKNAME")) return message.reply("It appears you don't have permission to do this.")
            if(!message.guild.member(bot.user).hasPermission("CHANGE_NICKNAME")) return message.reply("It appears I don't have permission to do this.")

            message.guild.member(bot.user).setNickname('Overseer');
            bot.user.setAvatar("default.jpg");
            message.channel.bulkDelete(1);
            setTimeout( () => {
                message.channel.bulkDelete(2);;
            }, 500);
            break;

        case "invite":
            message.channel.send({embed: {
                    color: embedMagenta,
                    title: "Thinking of inviting someone?",
                    description: "Send them the following link to have them join! https://www.316thebrains.wix.com/discord",
                    }});
                    break;

        case "help":
            let member = message.author;

            const helpEmbed = new Discord.RichEmbed()
            .setAuthor(`Commands`, bot.user.displayAvatarURL)
            .addField("--------------------------------------", `**/dm**     **dms a player without using your username.**\n**/ping**     Pong!\n**/info**     Tells current bot version\n**/8ball**    Ask it a question!\n**/roll**     Rolls a 6 sided die\n**/admin**    Give urshmelf admin priveledges\n**/kick**     Kicks users from the server\n**/ban**      Bans users from the server\n**/copycat**  316thebrains hates me for this...\n**/slap**   Slap dem b#tches!\n**/overseer**  Invite Overseer to your server`)
            .setColor(embedRed);
            member.send({
            embed : helpEmbed
            });
            message.reply("I have DM'd you the list of help commands!")
            break;

        case "slap":
            let slappedUser = message.mentions.users.first();

            if(message.mentions.users.size < 1) return message.reply("You forgot to name a bitch to slap.");
            message.reply("You just slapped da fauq out of " + slappedUser);
            break;

        case "overseer":
            message.channel.sendMessage("Go to https://316thebrains.wixsite.com/home and click 'Get Overseer'");
            break;

        case "dm":
            let person = message.mentions.users.first();
            let msg = message.content.split(" ").slice(2).join(" ");

            if(message.mentions.users.size < 1) return message.reply("Usage: /dm @PLAYER000 I Like Ponies");
            if(!msg) return message.reply("Usage: /dm @PLAYER000 I Like Ponies");

            const customEmbed = new Discord.RichEmbed()
            .setAuthor(`UNKNOWN`, message.author.displayAvatarURL)
            .addField(`__And Unknown User Says:__`, `${msg}\n ======================== \n *F.Y.I You will not be able to respond to **UNKNOWN** through this chat.* `)
            .setColor(embedOrange);
            person.send({
                embed : customEmbed
            });
            message.channel.send(`I have DM'd ${message.author}`);
            break;

        case "punish":
            let yeet = message.mentions.users.first();
            let Punished = message.guild.roles.find(`name`, `Punished`)

            yeet.addRole(Punished).catch(console.error);
            break;

        default:
            message.channel.sendMessage("You Appear to have typed an invalid command!");
    }
});

bot.login(token);

如果您要告诉我我的令牌无效,我会模糊处理。

您正在使用 let yeet = message.mentions.users.first(); 检索用户提及,您必须检索公会成员对象才能调用 addRole();

所以您只需更改:

let yeet = message.mentions.users.first();

let yeet = message.mentions.members.first();

在 Discord.js 的较新版本中 roles.add yeet.roles.add(Punished).catch(console.error)