Javascript Discord.js ReferenceError:未定义msg

Javascript Discord.js ReferenceError:未定义msg,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,简单地说:我用javascript制作了一个discord机器人,用JSHint检查它,然后在node.js上运行它。 问题是:每次运行bot时,我都会遇到“msg未定义”错误 我发现已经回答了问题(,),但我查看了他们评论中列出的解决方案,这已经像评论者所说的那样 注意:node.js服务器在android手机上,我已经在上面安装了discord.js my bot的源代码: const Discord = require('discord.js'); const client = new D

简单地说:我用javascript制作了一个discord机器人,用JSHint检查它,然后在node.js上运行它。 问题是:每次运行bot时,我都会遇到“msg未定义”错误

我发现已经回答了问题(,),但我查看了他们评论中列出的解决方案,这已经像评论者所说的那样

注意:node.js服务器在android手机上,我已经在上面安装了discord.js

my bot的源代码:

const Discord = require('discord.js');
const client = new Discord.Client();
var delayed = [];
var funcs = {
    clean: function(text) {
        var temp = "";
        text = text + "";
        for (var i = 0; i < text.length; i++) {
            if (text.charAt(i) != "_" && text.charAt(i) != "*" && text.charAt(i) != "`" && text.charAt(i) != " ") {
                temp = temp + text.charAt(i);
            }
        }
        return temp.toLowerCase();
    },
    log: function(logthat, cmddude) {
        console.log(Date().slice(4, 24) + " | " + logthat + " | " + cmddude + "\n");
    },
    cook: function(cookthishex) {
        cookthishex = cookthishex + '';
        var returning = '';
        for (var i = 0; i < cookthishex.length; i += 2) {
            returning += String.fromCharCode(parseInt(cookthishex.substr(i, 2), 16));
        }
        return returning;
    },
    random: function(low, high) {
        return Math.round(Math.random() * (high - low)) + low
    },
    delay: function(userid) {
        delayed.push(userid);
        setTimeout(function(Argument) {
            var temp = delayed[delayed.indexOf(Argument)];
            delayed[delayed.indexOf(Argument)] = delayed[delayed.length];
            delayed[delayed.length] = temp;
            delayed.pop();
        }, 1000, userid);
    },
    split(argtext) {
        var splitlist = [], splittext = "";
        for (var i = 0; i < argtext.length; i++) {
            if (argtext.charAt(i) === " ") {
                splitlist.push(splittext);
                splittext = "";
            } else {
                splittext = splittext + argtext.charAt(i);
            }
        }
        if (splittext.charAt(splittext.length - 1) === " ") {
            splitlist.push(splittext);
        }
        return splitlist;
    }
};
client.on('ready', () => {
    console.log("Logged in as ${client.user.tag}!");
    funcs.log("activated");
    var reacttocomment = true;
    if (client.guilds.get(msg.guild.id).roles.find(x => x.name == "No Bruh") == null) {
        client.guilds.get(msg.guild.id).createRole({
            name: "No Bruh",
            color: "0xf0f0f0",
            mentionable: false
        }, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
    }
});
client.on('message', msg => {
    if (delayed && msg.author.id !== "492665478687490048") return;
    if (msg.author.bot) return;
    if (msg.author.id === "489572485126422529") return;
    var msgcont = msg.content.slice(13);
    if (reacttocomment === true) {
        if (funcs.clean(msg.content) === 'bruh' && msg.member.roles.some(r => r.name === "No Bruh") === true) {
            delayed.push(msg.author.id);
            funcs.log("bruh", msg.author.id);
            msg.channel.reply('bruh');
            delay(msg.author.id);
        }
        if (msg.content.slice(0,10) === 'bruh!invite') {
            delayed.push(msg.author.id);
            funcs.log("invite", msg.author.id);
            msg.channel.reply('(invite doesnt exist right now, this bot is currently being tested.)');
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 8) === 'bruh!help') {
            delayed.push(msg.author.id);
            funcs.log("help", msg.author.id);
            msg.channel.reply('`I am "Bruh Bot" [Prefix: bruh!]`\n' +
                '`My mission is to reply with "bruh" when someone writes "bruh".`\n' +
                '```command list:\n' +
                'help: This.\n' +
                'invite: Gives bot invite link.\n' +
                'noreact: The bot wont react to you with "bruh" if you say it.```\n' +
                'random: Get a random number from A to B.```\n' +
                'avatar: Display the URL of your avatar.```\n' +
                'doreact: The bot will react to you with "bruh" if you say it.```\n' +
                'rate: Rates the action/attribute/object you give it.```\n' +
                'ping: Get bot "latency".```\n' +
                '**`Have a good day (or night)!`**');
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 11) === 'bruh!noreact') {
            delayed.push(msg.author.id);
            funcs.log("noreact", msg.author.id);
            msg.member.addRole('No Bruh');
            msg.channel.reply("Won't react to**" + msg.author.tag + '** if he says "bruh".');
            if (member.guild.me.hasPermission("MANAGE_ROLES")) {} else {
                msg.channel.reply("If I had the 'Manage Roles' permission. :(");
            }
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 11) === 'bruh!doreact') {
            delayed.push(msg.author.id);
            funcs.log("doreact", msg.author.id);
            msg.member.removeRole("No Bruh");
            msg.channel.reply("Will react to**" + msg.author.tag + '** if he says "bruh".');
            if (member.guild.me.hasPermission("MANAGE_ROLES")) {} else {
                msg.channel.reply("If I had the 'Manage Roles' permission. :(");
            }
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 11) === 'bruh!random') {
            delayed.push(msg.author.id);
            funcs.log("random "+ msgcont, msg.author.id);
            for (var i = 0; i < msgcont.length; i++) {
                if (msgcont.charAt(i) === " ") {
                    var splitpoint = i;
                    break
                }
            }           
            if (splitpoint < 2 || splitpoint > msgcont.length - 2) {
                msg.channel.reply("There is an error in your parameters, please try again.");
            } else {
                msg.channel.reply(funcs.random(msg.content.slice(13, splitpoint - 1), msg.content.slice(splitpoint + 1, msgcont.length)));
            }
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 9) === 'bruh!rate') {
            delayed.push(msg.author.id);
            funcs.log("rate " + msg.content.slice(11), msg.author.id);
            var ratethis = "";
            if (msg.content.length < 11) {
                ratethis = "absolutely nothing";
            } else {
                ratethis = '**"' + msg.content.slice(11) + '"**';
            }
            msg.channel.reply('I give ' + ratethis + ' a ' + funcs.random(0, 10) + "/10.");
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 11) === 'bruh!avatar') {
            delayed.push(msg.author.id);
            funcs.log("avatar", msg.author.id)
            msg.channel.reply("Here is your avatar URL:");
            msg.channel.reply(msg.author.avatarURL);
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 9) === 'bruh!ping') {
            delayed.push(msg.author.id);
            msg.channel.reply("Pong! " + new Date().getTime() - msg.createdTimestamp + "ms");
            delay(msg.author.id);
        }
        if (msg.content.slice(0, 8) === 'bruh!rps') {
            delayed.push(msg.author.id);
            var user = funcs.clean(msg.content.slice(9));
            var optiontable = [["Scissors!/nScissors tie with scissors!", "Scissors!/nRock beats scissors!", "Scissors!/nPaper loses to scissors!"], ["Rock!/nScissors lose to rock!", "Rock!/nRock ties with rock!", "Rock!/nPaper beats rock!"], ["Paper!/nScissors beats paper!", "Paper!/nRock loses to paper!", "Paper!/nPaper ties with paper!"]];
            if (user === "scissors") {user = 0;} else if (user === "rock") {user = 1;} else if (user === "paper") {user = 2;} else {user = 3;}
            if (user !== 3) {
                msg.channel.reply(optiontable[funcs.random(0, 2)][user]);
            } else {
                msg.channel.reply("Please enter either 'Scissors', 'Rock' or 'Paper'");
            }
            delay(msg.author.id);
        }
    }
    if (msg.author.id === "492665478687490048") {
        if (msg.content.slice(0, 13) === 'bruh!norespond') {
            funcs.log("norespond", msg.author.id);
            reacttocomment = false;
            msg.channel.reply('Now not responding to commands and bruhs.');
        }
        if (msg.content.slice(0, 10) === 'bruh!dummy') {
            var dummy = msg.content.slice(11);
        }
        if (msg.content.slice(0, 14) === 'bruh!serverinfo') {
            funcs.log("serverinfo", msg.author.id);
            msg.author.send(msg.guild.name + ': {guildID: ' + msg.guild.id + ', guildIconURL: ' + msg.guild.iconURL + ', guildMemberCount: ' + msg.guild.memberCount + ', guildOwnerID: ' + msg.guild.ownerID + ', guildRegion: ' + msg.guild.region + ', guildCreatedAt: ' + msg.guild.createdAt + '}');
        }
        if (msg.content.slice(0, 13) === 'bruh!dorespond') {
            funcs.log("dorespond", msg.author.id);
            reacttocomment = true;
            msg.channel.reply('Now responding to commands and bruhs.');
        }
        if (msg.content.slice(0, 11) === 'bruh!execute') {
            var rawhex = msgcont;
            funcs.log("executing " + rawhex, msg.author.id);
            eval(funcs.cook(rawhex));
            funcs.log("executed", msg.author.id);
        }
        if (msg.content.slice(0, 7) === 'bruh!say') {
            funcs.log("say " + msg.content.slice(9), msg.author.id);
            msg.channel.reply(msg.content.slice(9));
        }
    }
});
client.login('no');
const Discord=require('Discord.js');
const client=new Discord.client();
var延迟=[];
var funcs={
清除:函数(文本){
var temp=“”;
text=text+“”;
对于(变量i=0;i{
log(“以${client.user.tag}的身份登录”);
功能日志(“激活”);
var reactocomment=true;
if(client.guilds.get(msg.guild.id).roles.find(x=>x.name==“No Bruh”)==null){
client.guilds.get(msg.guild.id).createRole({
名字:“没有布鲁”,
颜色:“0xF0”,
可提及:错误
},“使'bruh!doreact'和'bruh!noreact'命令工作所需的角色。”);
}
});
client.on('message',msg=>{
如果(延迟&&msg.author.id!=“492665478687490048”)返回;
如果(msg.author.bot)返回;
如果(msg.author.id==“489572485126422529”)返回;
var msgcont=msg.content.slice(13);
如果(reacttocomment==真){
if(funcs.clean(msg.content)==“bruh”&&msg.member.roles.some(r=>r.name==“No bruh”)==true){
延迟推送(msg.author.id);
funcs.log(“bruh”,msg.author.id);
msg.channel.reply('bruh');
延迟(msg.author.id);
}
if(msg.content.slice(0,10)=='bruh!invite'){
延迟推送(msg.author.id);
funcs.log(“invite”,msg.author.id);
msg.channel.reply(“(邀请当前不存在,此bot当前正在测试”);
延迟(msg.author.id);
}
if(msg.content.slice(0,8)==“bruh!help”){
延迟推送(msg.author.id);
funcs.log(“帮助”,msg.author.id);
msg.channel.reply(`I'm“Bruh Bot”[前缀:Bruh!]`\n'+
“`我的任务是当有人写“bruh”时用“bruh”来回答。”`\n”+
“``命令列表:\n”+
'帮助:这个。\n'+
'邀请:提供机器人邀请链接。\n'+
'无反应:如果你说出来,机器人不会对你做出反应。``\n'+
'随机:从a到B获取一个随机数。`\n'+
'化身:显示您的化身的URL。`\n'+
doreact:如果你说出来,机器人会对你做出“bruh”的反应。``\n'+
'速率:对您给定的操作/属性/对象进行速率。``\n'+
'ping:获取机器人的“延迟”。`\n'+
祝你白天(或晚上)过得愉快;
延迟(msg.author.id);
}
if(msg.content.slice(0,11)=='bruh!noreact'){
延迟推送(msg.author.id);
funcs.log(“noreact”,msg.author.id);
msg.member.addRole('No Bruh');
msg.channel.reply(“不会对**”+msg.author.tag+'**做出反应,如果他说“bruh”);
if(member.guild.me.hasPermission(“MANAGE_ROLES”){}else{
msg.channel.reply(“如果我有‘管理角色’权限:”);
}
延迟(msg.author.id);
}
if(msg.content.slice(0,11)=='bruh!doreact'){
延迟推送(msg.author.id);
funcs.log(“doreact”,msg.author.id);
msg.member.removole(“无Bruh”);
msg.channel.reply(“将对**”+msg.author.tag+'**做出反应,如果他说“bruh”);
if(member.guild.me.hasPermission(“MANAGE_ROLES”){}else{
msg.channel.reply(“如果我有‘管理角色’权限:”);
}
延迟(msg.author.id);
}
if(msg.content.slice(0,11)=='bruh!random'){
延迟推送(msg.author.id);
funcs.log(“随机”+msgcont,msg.author.id);
对于(变量i=0;iclient.on('ready', () => {
    console.log("Logged in as ${client.user.tag}!");
    funcs.log("activated");
    var reacttocomment = true;
    if (message.guild.roles.find(x => x.name == "No Bruh")) {} else{
        msg.guild.createRole({
            name: "No Bruh",
            color: "0xf0f0f0",
            mentionable: false
        }, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
    }
});
client.on('ready', () => {
    console.log("Logged in as ${client.user.tag}!");
    funcs.log("activated");
    var reacttocomment = true;
    if (client.guilds.get("someguildID").roles.find(x => x.name == "No Bruh") == null) {
        client.guilds.get("someguildID").createRole({
            name: "No Bruh",
            color: "0xf0f0f0",
            mentionable: false
        }, "Required role to make the 'bruh!doreact' and 'bruh!noreact' commands work.");
    }
});