无法读取未定义的属性(读取成员)

Cannot read properties of undefined (reading members)

我正在尝试制作一个将用户包含在其中的嵌入命令,但每次我尝试 运行 它时,我都会收到关于读取 members 的错误,并且我'我不确定如何修复它。

const Discord = require('discord.js')

module.exports = {
  name: 'giveaway',
  description: 'sends giveaway info',
execute(client, message, args) {
    const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
    
    if(!args[0]) return message.channel.send('Please specify a user');
    
    if(!member) return message.channel.send('I can\'t seem to find this user.')
    
    const gaembed = new Discord.MessageEmbed()
    .setTitle('Congratulations', member)
    .setColor('GREEN')
    .setFooter('You have 24 hours from this message to claim your prize.')
    .setTimestamp()
    .setDescription('Congratulations! You have won a prize! Be sure to DM <@myuserid> to claim it, before it is rerolled.')
    message.channel.send(gaembed);
  },
};

这是我的 index 文件中的命令处理程序:

client.on('message', message => {
        
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(' ');
    const commandName = args.shift().toLowerCase();

    const command = client.commands.get(commandName)
        || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
    
    if(!command) return;
    
    try {
        command.execute(message, args, client)
    } catch (error) {
        console.error(error);
        message.reply('There was an error trying to execute that command! Check the console for more details!');
    }
});

您需要修正参数的顺序:

// wrong
execute(client, message, args) {

应该是这样的:

// correct
execute(message, args, client) {

就像在索引文件中一样,您可以按此顺序使用参数调用它 (command.execute(message, args, client))。