Reputation: 1
this is the error I get repeatedly please help! TypeError: command.execute is not a function
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);
and the relevant command that it doesnt work on
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)}`)
});
}
it works on all my othercommands, which are synchronous but it seems to break when i tried an async code. I also don't understand what the error means, let alone fix it. Thanks!
Upvotes: 0
Views: 8964
Reputation: 319
It seems as you are supposed to be using module.exports.execute = async (bot, message, args) => {
instead of module.exports.run = async (bot, message, args) => {
, as you are trying to use a execute function when it doesnt exist.
Upvotes: 1