Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.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在尝试踢自己时显示特定消息_Discord.js - Fatal编程技术网

discord.js在尝试踢自己时显示特定消息

discord.js在尝试踢自己时显示特定消息,discord.js,Discord.js,我试图创建一个踢用户的代码,但在某些情况下,我不希望用户能够踢另一个用户。其中一种情况是,要踢的用户与编写命令的用户相同。问题是我不能做这段代码,每次它告诉我:“你不能踢这个用户!”当它应该说:“你不能踢我自己”。当我试图踢自己时,我如何显示该消息? 另外,对不起我的英语,我是意大利人如果(member==message.author){替换为}else如果(member.id==message.author.id){ 这样,它将检查ID而不是成员/消息作者对象,ID将完全相同。替换}else

我试图创建一个踢用户的代码,但在某些情况下,我不希望用户能够踢另一个用户。其中一种情况是,要踢的用户与编写命令的用户相同。问题是我不能做这段代码,每次它告诉我:“你不能踢这个用户!”当它应该说:“你不能踢我自己”。当我试图踢自己时,我如何显示该消息? 另外,对不起我的英语,我是意大利人如果(member==message.author){替换为
}else如果(member.id==message.author.id){

这样,它将检查ID而不是成员/消息作者对象,ID将完全相同。

替换
}else if(成员===message.author){
}else if(成员.ID==message.author.ID){


通过这种方式,它将检查ID而不是成员/消息作者对象,ID将完全相同。

如果由于两个原因而未触发块,则您的
。首先,返回的是成员/消息作者对象的集合,而返回的是对象。您可以了解差异

其次,即使这两个对象的类型相同

console.log({}=={});//false
console.log({property:true}={property:true});//false

console.log({string:'something'}==={string:'something'});//false
if
块未触发有两个原因。首先,返回的是的集合,而返回的是一个对象。您可以了解其中的区别

其次,即使这两个对象的类型相同

console.log({}=={});//false
console.log({property:true}={property:true});//false
log({string:'something'}=={string:'something'});//false
const member = message.mentions.members.first()
if (!message.mentions.users.size) {
  return message.channel.send('You have to mention a user to kick him!');
} else if (member === message.author) {
  return message.channel.send('You can\'t kick yourself!');
} else if (!member.kickable) {
  return message.channel.send('You cannot kick this user!');
} else {
  return member
    .kick()
    .then(() => message.message.send(`${member.user.tag} was kicked.`))
    .catch(error => message.message.send(`Sorry, an error occured.`))
}