So I don’t wanna make a mess out of my Main.js so I try to make every possible command through module.exports in other documents.js
Basically I need that if I send a command, the bot will delete my message and post a comment+embed on a specific channel. This is what I have (making it simple):
module.exports = { name: 'chtest', execute(message, args, Discord) { let chComment = 'Normal comment'; chComment += 'nLine2'; message.channel.send(chComment) const chEmbed = blablaEmbedCode message.channel.send(chEmbed) message.delete(); },s };
I’ve read another Questions and they use
client.channels.cache.get(`Channel_ID`).send('Text')
I tried using it but I got an error ReferenceError: client is not defined
I added Client to my execute line:
execute(client, message, args, Discord) {
And now I have another error TypeError: Cannot read property 'cache' of undefined
And… I don’t know what to do now. Any solutions? Thank you in advance.
Advertisement
Answer
Try this using the Message
class’ client
property. Here are the docs for it.
module.exports = { name: 'chtest', execute(message, args, Discord) { let channel = message.client.channels.cache.get('CHANNEL_ID'); //channel is now the channel, unless it could not be found. channel.send('Message'); /*let chComment = 'Normal comment'; chComment += 'nLine2'; message.channel.send(chComment) const chEmbed = blablaEmbedCode message.channel.send(chEmbed) message.delete();*/ }, };