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

170
Visualizações
Estoy tratando de hacer que un bot de Discord envíe automáticamente una invitación de un solo uso cuando un usuario reacciona a mi mensaje. Soy un poco nuevo y me vendría bien ayuda :)

Copié el esqueleto de otro usuario e intenté editar algunas cosas, pero no puedo llevar el bot a un lugar donde, cuando reacciono con el mensaje, genera automáticamente el código y lo envía. Mis intenciones son reaccionar a un mensaje permanente y hacer que el destinatario reciba un DM del bot con un enlace único. Idealmente, solo pueden recibir el enlace una vez, incluso si se van y vuelven a unirse al canal. Estoy seguro de que tengo algunos errores importantes aquí para mi funcionalidad, ¡agradecería alguna orientación!

 const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const mySecret = process.env['token'] client.once('ready', () => { console.log('I am awake'); }); client.on('message', message => { if(reaction.message.name === "\:thumbsup:" || message.author.bot) return; const args = message.content.slice(prefix.length).split(' '); const command = args.shift().toLowerCase(); const replyWithInvite = async (message) => { let invite = await message.channel.createInvite( { maxAge: 10 * 60 * 1000, // maximum time for the invite, in milliseconds maxUses: 1 // maximum times it can be used }, `Requested with command by ${message.author.tag}` ) .catch(console.log); message.author.send(invite ? `Here's your invite: ${invite}` : "There has been an error during the creation of the invite."); } if (command === 'invite') { replyWithInvite(message); } }); client.login(mySecret);```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

El primer problema en tu código es tu evento. en

 const { Client, Intents } = require('discordjs'); require('dotenv').config() // If u're using environment variables for ur token const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_BANS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_BANS], partials: ['MESSAGE', 'CHANNEL', 'REACTION'] }); client.once('ready', () => { console.log('I am awake'); }); client.on('messageReactionAdd', async (reaction, user) => { // Check if the reaction is on ur intended message or just some random message on the server if (reaction.message.id != urMessageid) return; //check if the reaction is thumbsup or not if (reaction.emoji.name != 'thumbsup') return; // Create the invite now const defaultChannel = reaction.message.guild.channels.find(c=> c.permissionsFor(guild.me).has("SEND_MESSAGES")); let invite = await defaultChannel.createInvite({ maxAge: 10 * 60 * 1000, // maximum time for the invite, in milliseconds maxUses: 1 ,// maximum times it can be used reason: `Requested with command by ${user.tag}` }).then(invite => invite).catch(error => console.log(error)); user.send(`Here's your invite ${invite}`).catch(error => console.log(error)); }); client.login(process.env.TOKEN);

Puede encontrar algunos ejemplos de reacciones en la guía Discordjs V12 . También en una nota al margen para referencias futuras, no debe usar el evento de message ya que está en desuso . Puede usar client#messageCreate

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