[英]unban command with discord.js v12
I am trying to make an unban command but I get an error const member;
我正在尝试执行 unban 命令,但收到错误const member;
ERROR: Missing initializer in const declaration错误:在 const 声明中缺少初始化程序
client.on('message', async message => {
if (message.content.toLowerCase().startsWith(prefix + "unban"))
if (!message.member.hasPermission("BAN_MEMBERS")) {
return message.channel.send(`You cant use this command since you're missing "BAN_MEMBERS" perm`)
}
if (!args[0]) return (await message.channel.send('pls enter a users id to unban.')).then(msg => msg.delete({timeout: 5000}))
const member;
try {
member = await client.users.fetch(args[0])
} catch (e) {
console.log(e)
return message.channel.send(('an error accured'));
}
const reason = args[1] ? args.slice(1).join(' ') : 'no reason';
const newEmbed = new Discord.MessageEmbed()
.setFooter(`${message.author.tag} | ${message.author.id}`, message.author.displayAvatarURL({dynamic: true}))
message.guild.fetchBans().then( bans => {
const user = bans.find(ban => ban.user.id === member.id);
if (user) {
newEmbed.setTitle(`Successfully Unbanned ${user.user.tag}`)
.setColor('#FFFF00')
.addField({name: 'User ID', value: user.user.id, inline: true})
.addField({name: 'User Tag', value: user.user.tag, inline: true})
.addField({name: 'Banned Reason', value: user.reason})
message.channel.send(newEmbed)
}})})
const
means that the variable will be immutable (constant). const
意味着变量将是不可变的(常量)。 Thus, declaring a const
-type variable and not immediately assigning it a value is pointless, and not allowed in Javascript.因此,声明一个const
类型的变量而不立即为其赋值是没有意义的,并且在 Javascript 中是不允许的。
To make a mutable variable, instead of const
, you should use let
.要创建一个可变变量,而不是const
,您应该使用let
。
So, in your code, line 7 should look like this:因此,在您的代码中,第 7 行应如下所示:
let member;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.