TypeError:command.execute不是函数



这是我反复遇到的错误,请帮忙!TypeError:command.execute不是函数

const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.commands = 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);
}
const cooldowns = new Discord.Collection();
client.once('ready', () => {
console.log('Online!');
client.user.setActivity('~help | Aishiteimasu!', {type: 'PLAYING'});
});

client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName)
|| client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command.guildOnly && message.channel.type !== 'text') {
return message.reply('I can't execute that command inside DMs!');
}

if (command.args && !args.length) {
let reply = `Insufficient arguments provided!`;
if (command.usage) {
reply += `nThe proper usage would be: `${prefix}${command.name} ${command.usage}``;
}
return message.channel.send(reply);
}
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
console.log(command)
}
})
client.login(token); 

以及它在上不起作用的相关命令

const Discord = require("discord.js")
module.exports = {
name: "ping",
description: "Pong!",
cooldown: 5,
aliases: [ "latency", "uptime" ],
}
module.exports.run = async (bot, message, args) => {
message.channel.send("Pinging") .then(m => {
const ping = m.createdTimestamp - createdTimestamp
const choices = ["H-How was it?", "P-Please be good...", "I-I hope it isn't bad!"]
const response = choices[Math.floor(math.Random() * choices.length)]
m.edit(`${response}: Bot Latency: ${ping}, API Latency: ${Math.round(bot.ping)}`)
});
}   

它适用于我的所有其他命令,这些命令是同步的,但当我尝试异步代码时,它似乎会中断。我也不明白这个错误是什么意思,更不用说修复了。谢谢!

似乎应该使用module.exports.execute = async (bot, message, args) => {而不是module.exports.run = async (bot, message, args) => {,因为当执行函数不存在时,您正试图使用它。

最新更新