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

316
Views
Enviar un mensaje a un canal de texto cuando una persona se una a un canal de voz específico

Estoy tratando de hacer que mi bot notifique al personal de mi servidor en un canal de texto específico cuando alguien ingresa a la sala de espera de soporte de voz.

Desafortunadamente, solo encontré algunos ejemplos para la versión 12 de Discord, y no me funciona en la versión 13. No sé qué cambiar en ese código.

No hay mensaje de error ni nada, simplemente no envía un mensaje cuando alguien se une al canal de voz.

 client.on('voiceStateUpdate', (oldState, newState) => { const newUserChannel = newState.channelID; const textChannel = client.channels.cache.get('931223643362703521'); if (newUserChannel === '931156705303317013') { textChannel.send('Somebody joined'); } console.error(); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Primero, asegúrese de agregar las intenciones de GUILD_VOICE_STATES .

Probablemente sea mejor fetch el canal, en lugar de confiar en el caché. Si el canal ya está almacenado en caché, fetch lo usará y no realizará una solicitud a la API de discord, pero si no está almacenado en caché, channels.cache.get no lo encontrará.

Hice un par de cambios y agregué algunos comentarios en el siguiente código:

 const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES, ], }); client.on('voiceStateUpdate', async (oldState, newState) => { const VOICE_SUPPORT_ID = '931156705303317013'; const LOG_CHANNEL_ID = '931223643362703521'; // if there is no newState channel, the user has just left a channel const USER_LEFT = !newState.channel; // if there is no oldState channel, the user has just joined a channel const USER_JOINED = !oldState.channel; // if there are oldState and newState channels, but the IDs are different, // user has just switched voice channels const USER_SWITCHED = newState.channel?.id !== oldState.channel?.id; // if a user has just left a channel, stop executing the code if (USER_LEFT) return; if ( // if a user has just joined or switched to a voice channel (USER_JOINED || USER_SWITCHED) && // and the new voice channel is the same as the support channel newState.channel.id === VOICE_SUPPORT_ID ) { try { let logChannel = await client.channels.fetch(LOG_CHANNEL_ID); logChannel.send( `${newState.member.displayName} joined the support channel`, ); } catch (err) { console.error('❌ Error finding the log channel, check the error below'); console.error(err); return; } } });
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!