簡體   English   中英

使用 discord.js v12 解禁命令

[英]unban command with discord.js v12

我正在嘗試執行 unban 命令,但收到錯誤const member; 錯誤:在 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意味着變量將是不可變的(常量)。 因此,聲明一個const類型的變量而不立即為其賦值是沒有意義的,並且在 Javascript 中是不允許的。

要創建一個可變變量,而不是const ,您應該使用let

因此,在您的代碼中,第 7 行應如下所示:

let member;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM