Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

274
Visualizações
discord.js - guildMemberRemove doesn't work, guildMemberAdd works perfectly fine

Sorry if this is poorly formatted, I've never written a question on here before.

First of all, this is my first time writing anything in JavaScript, so this might be some dumb mistake I'm making that's causing my problem.

What I want to do is send a message when a member joins the server, and send a different message when a member leaves. When someone joins the server, the join message is sent and everything works perfectly fine, but when a member leaves, absolutely nothing happens. I put in some console.logs in the joinMessage and leaveMessage functions, and I get an output for joinMessage but nothing for remove. I have enabled Presence Intent and Server Members Intent on the Discord developer portal.

The join and leave message functions are down at the bottom, but I went ahead and added the entire thing so people could help me better. The bot token and channel IDs have been removed, and they are correct in my version of the code.

console.log('Starting');

const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const commandHandler = require("./commands");
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });
client.login('token');
var server = client.guilds.cache.get('server');

client.on('ready', ready);
function ready()
{
    console.log('Authenticated');
    server = client.guilds.cache.get('server');
}

client.on('messageCreate', receivedMessage);
function receivedMessage(msg)
{
    commandHandler(msg);
}


client.on('guildMemberAdd', joinMessage);
function joinMessage(member)
{
    let channelWelcome = server.channels.cache.get('welcome');
    let channelIntro = server.channels.cache.get('intro');
    channelWelcome.send(`Welcome to the server, ${member}! Head over to ${channelIntro} and introduce yourself!`); 
}


client.on('guildMemberRemove', leaveMessage);
function leaveMessage(member)
{
    let channelWelcome = server.channels.cache.get('welcome');
    channelWelcome.send(`${member} has left the server.`); 
}

I've been trying to figure this out for about an hour, so I'd really appreciate it if someone could help me solve this. Thanks!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to include following intent: GUILD_PRESENCES

So your code needs to look like this:

const client = new Discord.Client({ intents: [Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });

Now your bot will detect if a member leaves the guild.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try calling the function directly in the event parameters. There might be some sort of confliction when extracting the function

client.on("guildMemberAdd", (member) => {
    let channelWelcome = server.channels.cache.get('welcome');
    let channelIntro = server.channels.cache.get('intro');
    channelWelcome.send(`Welcome to the server, ${member}! Head over to ${channelIntro} and introduce yourself!`); 
}

client.on("guildMemberRemove", (member) => {
    let channelWelcome = server.channels.cache.get('welcome');
    channelWelcome.send(`${member} has left the server.`);
}

Also make sure you have set the right intents (if you are running V13), and gave the bot the correct privileged intents in the developer portal

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda