entitlementCreate triggers twice

Hello, I need help This code triggers twice as soon as I create a Test Entitlement via the REST API in Postman, is it because it is a Test Entitlement or should I approach this differently? The code is in my Bot.js outside of the client.on(ready) if important
client.on('entitlementCreate', async (entitlement) => {
logger.info(`New entitlement created for guild ${entitlement.guildId}`);

entitlementCache.set(entitlement.guildId, {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
});

const guildData = {
id: entitlement.guildId,
entitlement: {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
}
};
await insertEntitlement(guildData);
});
client.on('entitlementCreate', async (entitlement) => {
logger.info(`New entitlement created for guild ${entitlement.guildId}`);

entitlementCache.set(entitlement.guildId, {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
});

const guildData = {
id: entitlement.guildId,
entitlement: {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
}
};
await insertEntitlement(guildData);
});
2 Replies
d.js toolkit
d.js toolkit4mo 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!
NyR
NyR4mo ago
Make sure you do not have duplicate listeners or multiple instance of the bot running at the same time
Want results from more Discord servers?
Add your server