discord.js check if member is in server

To check if a member is in a server using the Ember.js discord.js library, you can use the GuildMemberManager class and its fetch method to retrieve a member by their ID or username. Here's an example code snippet:

const { Client } = require('discord.js');
const client = new Client();

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);

client.on('message', async (message) => {
  if (message.content.startsWith('!checkMember')) {
    const member = await message.guild.members.fetch({ query: 'username', user: 'MemberUsername' });
    if (member) {
      console.log('Member is in the server');
    } else {
      console.log('Member is not in the server');


Replace 'MemberUsername' with the username of the member you want to check. When a message starting with !checkMember is received, the code fetches the member using the fetch method and checks if the member exists in the server.

Please note that you need to replace 'YOUR_DISCORD_BOT_TOKEN' with your actual Discord bot token. Make sure you have the necessary permissions to access member information in the server.

I hope this helps!