![](/img/trans.png)
[英]TypeError: Cannot read property 'first' of undefined Discord.js node.js v12.16.3
[英]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.```"))
}
}
}
錯誤是:無法讀取未定義的“第一”屬性,它曾經可以工作,但由於某種原因它不會,有人可以幫助我嗎? 我一直在嘗試解決這個問題
您正在尋找
let channel = message.mentions.channels.first();
(注意復數channels
)
https://discord.js.org/#/docs/main/stable/class/MessageMentions?scrollTo=channels
https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=first
這是我朋友的一個簡單的錯字案例。
它應該是
let channel = message.mentions.channels.first();
由於 message.mentions.channels 是您嘗試訪問的屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.