I need help with my Discord bot, I am using discord.js
So I made this:
client.on("message", async(message) => {
if (!message.guild) return;
if (message.author.bot) return;
if (mentionn) {
const randomAmountOfCredits = Math.floor(Math.random() * 29) + 1; // Min 1, Max 30
(message.author.id, message.guild.id, randomAmountOfCredits);
if (collected.first().content === number) {
m.delete();
collected.first().delete();
credits[mentionn.id].credits += (+randomAmountOfCredits);
fs.writeFile(path, JSON.stringify(credits, null, 5), function(err) {
if (err) console.log(err)
});
if (collected.first().content !== number) {
return m.delete();
} else if (!mentionn) {
credits[author].credits += (+randomAmountOfCredits);
fs.writeFile(path, JSON.stringify(credits, null, 5), function(err) {
if (err) console.log(err)
});
}
}
}
});
It's like earning credits by each message sent, but I am not earning any credits, there are no errors on the console:
And here I must get credits, but nothing happens: Thats the results
I am a starter, thank you
I didn't understand a line of this code snippet, and I didn't understand your answer to Pascal Stockert's question, and neither did I understand what a
collected(from a collector?) var's doing here. but I'll try my best. This is how I would add this feature, feel free to mess around with this code and add as many conditions as you want.I didn't add it, but be careful, it looks like you don't handle the situation where
file[msg.author.id]doesn't exist.