我也是JavaScript的新手,也有不和谐的js,在运行不和谐的bot时出现错误,在这里,还请修复代码并告诉我我做错了,谢谢。
我一直在制造一个全功能的不和谐机器人,这是我发现的第一个错误,我无法修复,如果您能提供帮助,我将不胜感激。
let args = message.content.slice(prefix.length).trim().split(' ');
ReferenceError:消息未定义
// Constant Variables
const Discord = require("discord.js");
const prefix = "!";
const client = new Discord.Client();
// Startup 1 Below Listener Events
client.once("ready", () => {
console.log("Countless Is Up And Running, Wooohooo");
});
// Moderation 2 Below
client.on("Message", (Message) => {
if (Message.member.hasPermission(["KICK_MEMBERS"])) {
//console.log(message.content);
if (Message.content.startsWith(`${prefix}kick`)) {
//message.channel.send("Kick")
let member = Message.mentions.members.first();
member.kick().then((member) => {
Message.channel.send(
"https://gph.is/2iBA79h :wave: " +
member.displayName +
" has been kicked!"
);
});
}
}
});
client.on("Message", (Message) => {
if (Message.member.hasPermission(["BAN_MEMBERS"])) {
//console.log(message.content);
if (Message.content.startsWith(`${prefix}ban`)) {
//message.channel.send("Ban")
let member = Message.mentions.members.first();
member.ban().then((member) => {
Message.channel.send(
"https://gph.is/29507Ei :wave: " +
member.displayName +
" has been banned!"
);
});
}
}
});
// Variables
let args = message.content.slice(prefix.length).trim().split(" ");
let cmd = args.shift().toLowerCase();
// Return Statements
if (Message.author.bot) return; // Ignores All Bots
if (!Message.content.startWith(prefix)) return; // Returns Messages if doesnt start with the prefix
// Command Handler
try {
// Bonus: Auto-Reload ()
delete require.cache[require.resolve(`./commands/${cmd}.js`)];
let commandFile = require(`./commands/${cmd}.js`);
commandFile.run(client, Message, args);
} catch (e) {
// Will catch any errors within code or commands
console.log(e.stack);
}
client.login(token);
答案 0 :(得分:2)
JavaScript区分大小写。
<div class="login-box-body">
<!--Want to replace this text as Password Reset Was Success or add a new <p> tag containing the required words by hiding current <p> tag -->
<p class="login-box-msg">Enter your Email to reset the password</p>
<?php require '_inc/msg.php' ?>
<!-- Check if GET variable is set or not -->
<?php if (isset($_GET['code'])) {
echo '<style>.formPsw{ display:none;}</style>';
} ?>
<form action="" method="post" class="formPsw">
<div class="form-group has-feedback emailBox" >
<input type="email" name="email" class="form-control" placeholder="Email" data-validation="email required">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
</div>
<!-- /.col -->
<div class="col-xs-4 sendEmailBtn">
<input type="submit" name="send" class="btn btn-primary btn-block btn-flat" value="send"/>
</div>
<!-- /.col -->
</div>
</form>
<?php if (!empty($_POST['send'])) {
echo 'Please check your email ('.$_POST['email'].'). We send password reset link to your email.';
} ?>
</div>
在下面,您以大写的“ M”定义了消息参数。
所以您需要在消息中使用大写的M。
这是args V的解决方法
clinet.on("message", Message => {});
希望这会有所帮助。 ?
答案 1 :(得分:1)
该错误是不言自明的。您在一行上有message
,在另一行上有Message
。 JavaScript变量区分大小写。在这种情况下,您也无法在范围 message
之外定义client.on()
。我建议将所有需要消息的内容放入您的client.on('Message', Message => {}
范围内。
您可能也应该只使用一个范围。
答案 2 :(得分:1)
请确保将“ args”变量保留在client.on回调中。
赞:
client.on('message', message => {
let args = message.content.slice(prefix.length).trim().split(' ');
})