Is this the correct way to fetch the member?

I'm listening to the messageCreate event and am fetching the member. Is this the correct way / most optimal way to fetch the member.
client.on("messageCreate", async (msg) => {
const member = msg.guild?.members.cache.get(msg.author.id) ?? await msg.guild?.members.fetch(msg.author.id);
});
client.on("messageCreate", async (msg) => {
const member = msg.guild?.members.cache.get(msg.author.id) ?? await msg.guild?.members.fetch(msg.author.id);
});
4 Replies
d.js toolkit
d.js toolkit15mo 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
Cameron Campbell
Cameron CampbellOP15mo ago
Kinect3000
Kinect300015mo ago
message.member is the most concise way to do it in this case Discord provides the member data if applicable, so fetching isn’t necessary Attempting to fetch will just return the cached instance since it exists anyways
Cameron Campbell
Cameron CampbellOP15mo ago
oh ic, didn't realise that existed. thanks for the response btw 👍
Want results from more Discord servers?
Add your server