reading guilds TypeError

Hey,
const { Events } = require('discord.js');

module.exports = {
name: Events.ChannelUpdate,
once: false,
execute(oldChannel, newChannel, client) {
console.log(`${client.guilds.cache.size}`);
console.log(`channelUpdate: ${oldChannel.name} | ${newChannel.name}`);
}
};
const { Events } = require('discord.js');

module.exports = {
name: Events.ChannelUpdate,
once: false,
execute(oldChannel, newChannel, client) {
console.log(`${client.guilds.cache.size}`);
console.log(`channelUpdate: ${oldChannel.name} | ${newChannel.name}`);
}
};
show me an error. Can you pls help me?
No description
14 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
TÆMBØ
TÆMBØ13mo ago
You're likely not passing your client into your execute() function for your event handler, nor do you really need to since just about all d.js structures have a client property
</PixelPatron>
</PixelPatron>OP13mo ago
Then why doesn't it work? I don't understand the problem
TÆMBØ
TÆMBØ13mo ago
My first sentence explains why your code is not functioning
</PixelPatron>
</PixelPatron>OP13mo ago
So I don't need to pass 'client'? Because all DJs have one? That's what I read.
TÆMBØ
TÆMBØ13mo ago
Correct, just use oldChannel.client Or newChannel, doesn't matter since both are channel instances that have it
</PixelPatron>
</PixelPatron>OP13mo ago
ok and how do I access a channel within the event so that I can send a message?
TÆMBØ
TÆMBØ13mo ago
Assuming you have the Guilds intent, <Client>.channels.cache.get(channelId) to get the channel you want
d.js docs
d.js docs13mo ago
:method: TextBasedChannel#send() Sends a message to this channel.
</PixelPatron>
</PixelPatron>OP13mo ago
I'm asking because the original goal was to send a message in a channel when someone creates a new channel. However, I was never able to access the channel list. So I wanted to work on it bit by bit. And with oldchannel before?
TÆMBØ
TÆMBØ13mo ago
To get to the Client, yes
</PixelPatron>
</PixelPatron>OP13mo ago
aaaaaaaah .. I understand .. pretty easy ..
d.js docs
d.js docs13mo ago
:property: GuildChannel#client The client that instantiated this
</PixelPatron>
</PixelPatron>OP13mo ago
Thank you so Mitch Mutch

Did you find this page helpful?