[英]TypeError: Cannot read property 'has' of undefined // Discord.js
所以,我正在為我的 Discord 服務器創建一個機器人。 我得到了這個錯誤。 請記住,我是一個業余愛好者:)。 在此先感謝,不勝感激^^。
const config = require('../config.js');
module.exports = message => {
let client = message.client;
if (message.author.bot) return;
if (!message.content.startsWith(config.prefix)) return;
let command = message.content.split(' ')[0].slice(config.prefix.length);
let params = message.content.split(' ').slice(1);
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
};
if (cmd) {
if(!message.guild) {
if(cmd.config.guildOnly === true) {
return;
};
};
if (cmd.config.permLevel) {
if(cmd.config.permLevel === "BOT_OWNER") {
if(!config.geliştiriciler.includes(message.author.id)) {
message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
return;
}
}
if(!message.member.hasPermission(cmd.config.permLevel)) {
message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
return;
};
};
cmd.run(client, message, params);
};
};
在第 7 行,請試試這個
const cmd =
message.client.commands.get(command) ||
message.client.commands.find(
(cmd) => cmd.aliases && cmd.aliases.includes(command) // if you're also using aliases
);
if (!command) return;
添加一些布爾值來檢查 client.commands/client.aliases 是否未定義。
if (client.commands && client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases && client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.