我是 repl.it 上的 discord.js 初学者
代码:
client.on("message", async (message) => {
if(message.content.startsWith("!mute")) {
if(message.member.hasPermission("ADMINISTRATOR")) {
let member = message.mentions.members.first()
if(!member) message.channel.send("mention someone to mute!")
else {
member.roles.add("813876389475385394")
let embed = new Discord.MessageEmbed()
.setTitle("Kicks")
.setDescription(`${victim} got kicked by ${message.author}!`)
.setColor("GREEN")
.setFooter(`Moderator : ${message.author.username}`)
.setTimestamp()
message.channel.send(embed)
}
});
但是控制台会发送这样的错误:
/home/runner/lifeafterbot/index.js:71
});
^
SyntaxError: Unexpected token ')'
Hint: hit control+c anytime to enter REPL.
谁能看出我错在哪里?
答案 0 :(得分:1)
我已经整理了您的格式,现在应该可以使用了
client.on("message", async (message) => {
if(message.content.startsWith("!mute")) {
if(message.member.hasPermission("ADMINISTRATOR")) {
let member = message.mentions.members.first()
if(!member) {
message.channel.send("mention someone to mute!")
} else {
member.roles.add("813876389475385394")
let embed = new Discord.MessageEmbed()
.setTitle("Kicks")
.setDescription(`${victim} got kicked by ${message.author}!`)
.setColor("GREEN")
.setFooter(`Moderator : ${message.author.username}`)
.setTimestamp()
message.channel.send(embed)
};
};
};
});
确保正确缩进代码,也许可以下载像 Visual Studio Code 这样的 IDE,这对格式化有很大帮助。
你还应该尽量减少嵌套语句,你可以像这样把它们剪短:
if(!message.member.hasPermission("ADMINISTRATOR")) return; //the '!' operator means the returned value is false if the user does not have admin the command is cancelled