Message doesn't send to channel

client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync(join(__dirname, 'messages.json'), 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync(join(__dirname, 'messages.json'), 'utf8'));

// Get a random join message index
const randomIndex = Math.floor(Math.random() * jsonData.joinMessages.length);

// Get the random join message
const randomJoinMessage = jsonData.joinMessages[randomIndex];

console.log(randomJoinMessage);

// Insert the user's username into the join message
const formattedJoinMessage = randomJoinMessage.replace("{userName}", member.user.username);

console.log(formattedJoinMessage);

const channel = client.channels.cache.get('1174309146816950303'); // #new-beavers
if (channel && channel.type == ChannelType.GuildText) {
channel.send(formattedJoinMessage);
console.log ("message sent");
}
});
basically, all the log messages appear EXCEPT for message sent, and the message is not sent to the channel. the channel id is correct
2 Replies
d.js toolkit
d.js toolkit7mo 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
samp
samp7mo ago
yes yes I logged the channel, and apparently it's undefined maybe client.channels.cache.get('1174309146816950303') is incorrect somehow? oh THAT might be it guilds intent I have GUILD_MEMBERS intent, but nothing else i guess i need GatewayIntentBits.Guilds intent oh. YEAH IT WORKED