Почему я получаю TypeError: не удается прочитать свойство ‘execute’ неопределенного

#javascript #discord.js

#javascript #discord.js

Вопрос:

Эй, итак, я пытался создать бота Discord, в духе Рождества, у него будет команда «.suggestgift», которая запустит приглашение, которое определит подходящее соответствие для человека. Я продолжаю получать сообщение об ошибке: «TypeError: не удается прочитать свойство ‘execute’ неопределенного… Я не знаю, почему, хотя другие команды, написанные одинаково, похоже, работают. Вот мой код…

 const Discord = require('discord.js');
const WOKCommands = require ('wokcommands');
const client = new Discord.Client();

const prefix = '.';

const fs = require('fs');

client.commands = new Discord.Collection();
client.commands.giftsuggest = new Discord.Collection()


const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}


client.once('ready', () => {
    console.log('Santa bot is online');
});

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

    const args = message.content.slice(prefix.length).split(/  /);
    const command = args.shift().toLowerCase();

    if(command === 'clear'){
        client.commands.get('clear').execute(message, args, Discord);
    } else if(command === 'kick'){
        client.commands.get('kick').execute(message, args, Discord);
    } else if(command === 'ban'){
        client.commands.get('ban').execute(message, args, Discord);
    }else if(command === 'ping'){
        client.commands.get('ping').execute(message, args, Discord);
    }else if(command == 'giftprompt'){
        client.commands.giftsuggest.get('giftprompt').execute(message, args);
    }

    
});



client.login('my token would be here')
 

Код файлов:

 module.exports = {
    name: 'suggestprompt',
    description: 'testing',
    execute(message, args){
        message.channel.send('This is testing to see that the command works')
    }
}
 

Ответ №1:

module.exports возвращает объект, который является парой ключ-значение, вам не хватает ключевой части для функции execute

попробуйте изменить значение module.exports ниже

 module.exports = {
    name: 'suggestprompt',
    description: 'testing',
    execute: function(message, args){
        message.channel.send('This is testing to see that the command works')
    }
}
 

И добро пожаловать в StackOverflow 🙂