Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord.js TypeError:message.member.hasPermissions不是函数_Discord.js_Javascript_Node.js_Discord - Fatal编程技术网

Discord.js TypeError:message.member.hasPermissions不是函数

Discord.js TypeError:message.member.hasPermissions不是函数,discord.js,javascript,node.js,discord,Discord.js,Javascript,Node.js,Discord,我想发出一个unban命令,但在执行过程中仍然会出现一些错误,我不知道该怎么办 TypeError:message.member.hasPermissions不是我得到的错误函数 请帮帮我。我是一名初学者,以下是我的unban.js代码: const Discord = require('discord.js'); const client = new Discord.Client(); const embed = new Discord.MessageEmbed() .setColor('#

我想发出一个unban命令,但在执行过程中仍然会出现一些错误,我不知道该怎么办

TypeError:message.member.hasPermissions不是我得到的错误函数

请帮帮我。我是一名初学者,以下是我的unban.js代码:

const Discord = require('discord.js');
const client = new Discord.Client();

const embed = new Discord.MessageEmbed()
.setColor('#0B15A3')

module.exports = {
  name: 'unban',
  description: "This unbans a user",
  execute(message, args, client, Discord) {
      
      if (message.member.hasPermissions("BAN_MEMBERS") ){
          if (!isNaN(args[0])) {
            const bannedMember = message.guild.members.cache.get(args[0]) // Get the `member` property instead to recall later.
            var reason = args.slice(1).join(" ");
            if(!reason) {
              reason = "No reason given!"
            }
            if (bannedMember) {
              bannedMember
                message.guild.members.unban(bannedMember.id, reason)
                .then(() => {
                  embed.setDescription(`Successfully unbanned **${bannedMember.user.tag}**`); // `user` is undefined.
                  message.channel.send(embed);
                })
                .catch(err => {
                  embed.setDescription('I was unable to unban the member');
                  message.channel.send(embed);
                  console.error(err);
                });
            } else {
              embed.setDescription("That user isn't in this guild!");
              message.channel.send(embed);
            }
          } else {
            embed.setDescription("You need to provide an user ID to unban");
            message.channel.send(embed);
          }
      } else {
        embed.setDescription("You do not have `BAN_MEMBERS` permissions to unban this member");
        message.channel.send(embed);
      }
  }
}
这是我的index.js代码:

const Discord = require('discord.js');

const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});

const prefix = '-';

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command)
}



client.once('ready', () => {
    console.log(`${client.user.tag} is online!`);


    client.user.setPresence({
     status: 'online',
     activity: {
         name: "Prefix: -",
         type: "PLAYING"
     }
 });
});

client.on('message', message =>{
   if(!message.content.startsWith(prefix) || message.author.bot) return;

   const args = message.content.slice(prefix.length).split(/ +/);
   const command = args.shift().toLowerCase();

   if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
   } else if(command === 'invite'){
        client.commands.get('invite').execute(message, args, Discord);
   } else if(command === 'help'){
        client.commands.get('help').execute(message, args, Discord);
   } else if(command === 'clear'){
        client.commands.get('clear').execute(message, args);
   } else if(command === 'nuke'){
        client.commands.get('nuke').execute(message, args, Discord);
   } else if(command === 'supersecretrules'){
        client.commands.get('supersecretrules').execute(message, args, Discord);
   } else if(command === 'support'){
        client.commands.get('support').execute(message, args, Discord);
   } else if(command === 'kick'){
        client.commands.get('kick').execute(message, args);
   } else if(command === 'ban'){
        client.commands.get('ban').execute(message, args);
   } else if(command === 'unban'){
        client.commands.get('unban').execute(message, args);
   }
     
});

client.login('token');

你能帮我吗?提前谢谢

你犯了一个打字错误。它是而不是
haspowpermissions()

const Discord=require('Discord.js');
const client=new Discord.client();
const embed=new Discord.MessageEmbed()
.setColor(“#0B15A3”)
module.exports={
名称:“unban”,
description:“此取消绑定用户”,
执行(消息、参数、客户端、不一致){
if(message.member.hasPermission(“BAN_成员”)){
如果(!isNaN(args[0])){
const bannedMember=message.guild.members.cache.get(args[0])//获取'member'属性,以便稍后调用。
var reason=args.slice(1.join)(“”);
如果(!原因){
reason=“没有给出任何理由!”
}
如果(横幅成员){
横幅成员
message.guild.members.unban(bannedMember.id,原因)
.然后(()=>{
embed.setDescription(`Successfully unbanned**${bannedMember.user.tag}**`);//`user`未定义。
message.channel.send(嵌入);
})
.catch(错误=>{
embed.setDescription('我无法取消对成员的绑定');
message.channel.send(嵌入);
控制台错误(err);
});
}否则{
embed.setDescription(“该用户不在此帮会中!”);
message.channel.send(嵌入);
}

您犯了一个简单的排版错误。正确的函数名为

更改:

message.member.hasPermissions(“禁止成员”)
致:

message.member.hasPermission(“禁止成员”)

什么不起作用?你遇到了什么错误?请补充问题:)打字错误,这是
消息。member.hasPermission
,单数:typearError:message.member.hasPermissions不是一个函数,这是我的错误,我得到了。请帮助我,这对我来说很重要。你能再帮我一件事吗但现在,当我试图解封一个我禁止我的机器人发送的用户时,该用户不在这个公会中!我该怎么办?–@dshre这看起来与这个问题无关,你应该但是请不要忘记添加所有相关代码,这样我们就可以查看它了。谢谢,这对我来说意义重大。你能帮我做一件事吗,这样它就不会给我了这是一个错误,但现在当我尝试解除某人的绑定时,我禁止了我的bot发送该用户不在该公会中!我该怎么办?我会尝试使用
wait message.guild.members.fetch()获取该用户
然后试着解开他的枷锁。有关更多信息,您也可以查看以下页面:很抱歉让您感到痛苦,您可能有事情要做,但我真的不知道该将这段代码放在哪里。这意味着很多。这对我来说意义重大。您还可以帮我做一件事吗?这样它就不会给我那个错误,但现在当我试图解除某人的绑定时,我禁止了我的bot发送该用户不在此帮会中!我该怎么办?–您可以使用带有id的解除绑定方法。例如:
message.guild.members.unban(“用户id”);