[英]discord.js Cannot read property 'first' of undefined
name: 'purge',
description: "Purge messages from the chat.",
execute(message, args, Discord){
const Error = new Discord.MessageEmbed()
.setTitle("Correct Usage")
.setColor('#4e5d94')
.setDescription("```>purge [integer] [<channel>]```");
if(message.member.permissions.has("MANAGE_MESSAGES")){
if(!args[0]) return message.reply(Error);
if(isNaN(args[0])) return message.reply(Error);
if(args[0] > 150) return message.reply(Error.setDescription("```Integer should be smaller than 150```".setTitle("Error")));
if(args[0] <= 0) return message.reply(Error.setDescription("```Integer should be bigger than 0```").setTitle("Error"));
if(args[1]){
try{
let channel = message.mentions.channel.first();
channel.bulkDelete(args[0]);
message.channel.send(Error.setTitle("Cleared").setDescription("```Successfully cleared " + args[0] + " messages from " + channel + "```"))
}catch(e){
console.log(e)
message.reply(Error.setTitle("Error").setDescription("```Client has run into a problem , please contact the developers.```"))
}
} else{
message.channel.bulkDelete(args[0]);
message.channel.send(Error.setTitle("Cleared").setDescription("```Successfully cleared " + args[0] + " messages```"))
}
} else{
message.reply(Error.setTitle("Permission").setDescription("```Insufficient permission.```"))
}
}
}
the error is : Cannot read property 'first' of undefined it used to work but for some reason it just wont no , can anyone help me?错误是:无法读取未定义的“第一”属性,它曾经可以工作,但由于某种原因它不会,有人可以帮助我吗? i have been trying to fix this thing for a bit now
我一直在尝试解决这个问题
You're looking for您正在寻找
let channel = message.mentions.channels.first();
(notice the plural channels
) (注意复数
channels
)
https://discord.js.org/#/docs/main/stable/class/MessageMentions?scrollTo=channels https://discord.js.org/#/docs/main/stable/class/MessageMentions?scrollTo=channels
https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=first https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=first
It is a simple case of Typo my friend.这是我朋友的一个简单的错字案例。
It should be它应该是
let channel = message.mentions.channels.first();
Since message.mentions.channels is the property which you are trying to access.由于 message.mentions.channels 是您尝试访问的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.