Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
Bot de Discord para enviar un mensaje si un determinado miembro se conecta

He estado investigando en los últimos días, pero no pude encontrar literalmente nada. Lo mismo en pitón.

 const Discord = require("discord.js") const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] }) const member = client.guilds.cache.get("person_id") // person I want to check client.on("ready", () => { console.log(`Logged in as ${client.user.tag}!`) }) client.on("message", msg => { if (msg.content === "ping") { msg.reply("pong"); } }) // everything worked to this moment client.on("presenceUpdate", () => { if (member.presence.status === 'online') { client.channels.cache.get("channel_id").send("HELLO"); // message i want bot send to the channel if member goes online } }); client.login('***')

Si agrego la intención GUILD_PRESENCES , recibo el siguiente error:

 if (member.presence.status === 'online') { ^ TypeError: Cannot read properties of undefined (reading 'presence')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Primero, deberá habilitar la intención GUILD_PRESENCES si desea utilizar el evento de actualización de presenceUpdate .

En segundo lugar, client.guilds.cache.get("person_id") no devuelve un miembro. guilds.cache es una colección de gremios, no miembros.

Y por último, la actualización de presenceUpdate activa cada vez que cambia la presencia de un miembro (por ejemplo, estado, actividad). Significa que su presence puede ser la misma (por ejemplo, en línea), pero el evento aún se activa, por lo que verificar if (member.presence.status === 'online') no funcionará. En su lugar, lo que puede hacer es comparar las presence antiguas y nuevas. Puede encontrar el código a continuación y he agregado algunos comentarios para que quede un poco más claro.

 const Discord = require('discord.js'); const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_PRESENCES'], }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('presenceUpdate', (oldPresence, newPresence) => { // if someone else has updated their status, just return if (newPresence.userId !== 'person_id') return; // if it's not the status that has changed, just return if (oldPresence.status === newPresence.status) return; // of if the new status is not online, again, just return if (newPresence.status !== 'online') return; try { client.channels.cache.get('channel_id').send('HELLO'); } catch (error) { console.log(error); } }); client.login('***');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!