Giving users one coin, when they join a server through a command.

The bot rewards users with coins each time they join a server from a command "farm" The bot automatically tracks when a user joins one of these servers and adds a coin to their account (using MongoDB). The code im using for this is given down below! The issue is that the bot just dosent adds acoin to the database automatically... Code:
// Update the farm entry to increment membersJoined count
farm.membersJoined += 1;
await farm.save();
console.log('Updated farm membersJoined count:', farm.membersJoined);

// Find or create the user in the database
let user = await User.findOne({ userId: userId });
if (!user) {
// Set initial balance to 1 coin
user = new User({
userId: userId,
coins: 1 // Initial balance for new users
});
console.log('New user created with initial coins:', user.coins);
} else {
user.coins += 1; // Add 1 coin for joining
console.log('Existing user updated with new coin balance:', user.coins);
}
await user.save();
// Update the farm entry to increment membersJoined count
farm.membersJoined += 1;
await farm.save();
console.log('Updated farm membersJoined count:', farm.membersJoined);

// Find or create the user in the database
let user = await User.findOne({ userId: userId });
if (!user) {
// Set initial balance to 1 coin
user = new User({
userId: userId,
coins: 1 // Initial balance for new users
});
console.log('New user created with initial coins:', user.coins);
} else {
user.coins += 1; // Add 1 coin for joining
console.log('Existing user updated with new coin balance:', user.coins);
}
await user.save();
Any help i could get to fix that? I can provide more codes if needed
2 Replies
d.js toolkit
d.js toolkit2mo 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
Txslx
TxslxOP2mo ago
oh okay
Want results from more Discord servers?
Add your server