Reputation: 13
I am trying to make a command to clear messages in my discord and I receive the error message is not defined. Above the error inside of the terminal there is one specific portion under my return
for the first line with it, there is an arrow pointing up to it.
Here is my code for the main portion
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '!';
const fs = require('fs');
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);
}
client.once('ready', () => {
console.log('Codelyon 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 == 'ping') {
client.commands.get('ping').execute(message, args);
}
else if(command == 'ouryoutube') {
client.commands.get('youtube').execute(message, args);
}
else if(command == 'clear') {
client.commands.get('clear').execute(message, args);
}
});
Here is my code for the command
module.exports = {
name: 'clear',
description: "Clear Messages",
execute(messages, args) {
if(!args[0]) return message.reply("You must enter the number of messages you want to clear");
if(isNaN(args[0])) return message.reply("Please Enter a Real Number.");
if(args[0] > 100) return message.reply("You can't delete more then 100 messages");
if(args[0] < 1) return message.reply("You must delete at least one message");
}
}
Thank you any help is appreciated! :)
Upvotes: 0
Views: 273
Reputation: 11915
You have a typo in execute(messages, args) {...}
. The first argument should be message
.
execute(message, args) {
// code
}
Upvotes: 1