Txslx
Txslx
DIAdiscord.js - Imagine an app
Created by Txslx on 10/26/2024 in #djs-questions
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
3 replies