Reputation: 35
I have a command that clears a set amount of messages that works fine right now, but I'm trying to have the bot send a message to a log channel that tells the mods and admin, how many messages were deleted and who deleted them. This is all the code right now from the clear file:
module.exports = {
name: 'clear',
description: "clears messages",
async execute(message, args){
if(message.member.roles.cache.has('802911784892760074')){//If mod
if(!args[0]) return message.reply('Enter amount');
if(isNaN(args[0])) return message.reply('Enter amount');
if(args[0] > 100) return message.reply('To high');
if(args[0] < 1) return message.reply('To low');
await message.channel.messages.fetch({limit: args[0]}).then(messages =>{
message.channel.bulkDelete(messages);
client.channels.cache.get('799292569825443860').send(`${message.author} has cleared ${args} messages!`)
});
}
}
This is the line of code that does not seem to be working:
client.channels.cache.get('799292569825443860').send(`${message.author} has cleared ${args} messages!`)
The command prompt says that the client is not defined, but I have the clientdefined in the main js file.
const client = new Discord.Client();
I'm still pretty new to this, and I may just be missing something very basic. (and I'm sorry if this question comes off as stupid to those who understand) any help would be awesome, as I seem to be at a roadblock here.
Upvotes: 2
Views: 32
Reputation: 642
You need to pass your client
object to the function, so for example you could do this:
client.commands.get('clear').execute(message, args, client);
(or however you execute commands), and then have your function definition like this: async execute(message, args, client){
Upvotes: 1
Reputation: 23160
That client
won't just magically appear in your command's file. You need to pass the client
as an argument:
async execute(message, args, client){
// ...
And in main.js
:
commands.get('clear').execute(message, args, client)
Upvotes: 1