我的禁止命令不起作用。有人可以帮我吗?对我来说很重要 这是我的第一个机器人,我希望它真的很不错。
代码:
module.exports = {
name: "ban",
aliases: ["banuser"],
execute(client, message, args) {
if (message.member.hasPermission("BAN_MEMBERS")) let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if (!User) return message.channel.send("Meg kell nevezned egy szemelyt!")
if (User.hasPermission("BAN_MEMBERS")) return message.reply("Nem tudtam kitiltani a felhasznalat")
let banReason = args.join(" ").slice(22);
if (!banReason) banReason = "None"
User.ban({reason: banReason})
}
}
错误:
C:\Users\marce\Discord Bot\commands\ban.js:6
let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
^^^
SyntaxError: Lexical declaration cannot appear in a single-statement context
答案 0 :(得分:0)
您需要在if
函数之前声明变量。例如:
if (1+1===2) let test = 1 // this will return an error
let test;
if (1+1===2) test = 1 // this will not return an error
根据您的情况,您需要进行更改
if (message.member.hasPermission('BAN_MEMBER') let User = // ...
到
let User;
if (message.member.hasPermission('BAN_MEMBER') User = // ...