Join messages don't want to work?

For some reason, it can't read "messages.json" because it's not valid directory...but it's right there?
client.on(Events.GuildMemberAdd, async (member) => {
if (member.guild.id != GUILD_ID) return;

// Read the JSON file
const jsonData = JSON.parse(readFileSync("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("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");
}
});
6 Replies
d.js toolkit
d.js toolkit6mo 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 staff
samp
samp6mo ago
No description
treble/luna
treble/luna6mo ago
this does not look djs related
samp
samp6mo ago
oh yeah sorry
treble/luna
treble/luna6mo ago
and readfilesync takes the root dir iirc
samp
samp6mo ago
i tried ./messages.json and that didn't work either anyways i'll move it to #other-js-ts