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 toolkit8mo 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
MightyPart
MightyPart8mo ago
discord.js@14.13.0 && v20.4.0
Kinect3000
Kinect30008mo 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
MightyPart
MightyPart8mo ago
oh ic, didn't realise that existed. thanks for the response btw 👍