Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.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
Javascript Discord.JS TypeError:message.author.hasPermission不是函数_Javascript_Node.js_Discord.js - Fatal编程技术网

Javascript Discord.JS TypeError:message.author.hasPermission不是函数

Javascript Discord.JS TypeError:message.author.hasPermission不是函数,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我当时正在为discord.js bot编写一个命令,在编写命令命令(打开/关闭命令)时,我遇到了一些错误 当我使用.hasPermission函数时,我在标题中遇到了错误: TypeError:message.author.hasPermission不是一个函数 我不认为我的代码有问题,因为构造函数可以处理其他命令,但我愿意接受建议。我的代码如下: module.exports={ 名称:'模块', 说明:“打开/关闭命令”, 执行(消息,参数){ //必需的 const Discord=re

我当时正在为discord.js bot编写一个命令,在编写
命令
命令(打开/关闭命令)时,我遇到了一些错误

当我使用
.hasPermission
函数时,我在标题中遇到了错误:

TypeError:message.author.hasPermission不是一个函数

我不认为我的代码有问题,因为构造函数可以处理其他命令,但我愿意接受建议。我的代码如下:

module.exports={
名称:'模块',
说明:“打开/关闭命令”,
执行(消息,参数){
//必需的
const Discord=require('Discord.js');
const db=require('quick.db')
var randomExt=require('random-ext');
//所需端
var命令=['changelog'、'invite'、'prefix'、'balance'、'bankrob'、'beg'、'deposit'、'gamble'、'job'、'rob'、'work'、'afk'、'avatar'、'botinfo'、'serverinfo'、'userinfo'、'level'、'setlevel'、'ban'、'kick'、'mute'、'purge'、'unban'、'unmute'、'warn'、'warning']
让user=message.author;
让命令选择;
const permissionEmbed=new Discord.MessageEmbed()
.setTitle('您没有执行此操作的权限')
const commandFail=new Discord.MessageEmbed()
.setTitle('没有具有该名称的命令!')
const argsError=new Discord.MessageEmbed()
.setTitle('用法:`command`'))
const completeEmbed=new Discord.MessageEmbed()
.setTitle(`Command\`${args[0]}`现在是\`${args[1]}`)
如果(!message.author.hasPermission('ADMINISTRATOR')){
返回message.channel.send(permissionEmbed);
}else if(user.hasPermission('ADMINISTRATOR')){
如果(!args[0]| |!args[1]){
返回message.channel.send(argsError);
}else if(args[0]!='on'&args[0]!='off'){
返回message.channel.send(argsError);
}
对于(i=0;i>commands.length;i++){
if(args[0]==命令[i]){
return commandSelect=命令[i];
}
}
if(commandSelect=null | | commandSelect==未定义){
返回message.channel.send(commandFail);
}否则{
db.set(`${message.guild.id}.${commandSelect}`,'false'))
返回message.channel.send(completeEmbed);
}
}
},
};

我还认为值得一提的是,当我使用参数运行命令时,
p!命令ban off
,我得到一个错误
类型错误:Discord.MessasgeEmbed不是构造函数

消息。author
返回一个和
消息。member
返回一个;作为公会成员的消息作者

Discord
用户
s没有权限,帮会
成员
s有权限。您只能检查成员是否具有某些权限,因此您需要将代码更改为:

if(!message.member.hasPermission('ADMINISTRATOR')){
返回message.channel.send(permissionEmbed);
}
//您不需要else或else,因为此部分仅在成员
//他是管理员
如果(!args[0]| |!args[1]){
返回message.channel.send(argsError);
}else if(args[0]!='on'&args[0]!='off'){
返回message.channel.send(argsError);
}
// ...