Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
handledPromiseRejectionWarning: TypeError: Cannot read property 'add' of undefined (Discord Bot)

I have been dealing with an issue with my discord bot captcha. The captcha works really well but when it comes to adding a role if they verified it slaps me with

handledPromiseRejectionWarning: TypeError: Cannot read property 'add' of undefined

This is my code:

const Discord = require('discord.js-12');

const client = new Discord.Client();

const prefix = 'ri-';

const Captcha = require("@haileybot/captcha-generator");

client.once('ready', () => {
    console.log('Ready!');
});
let captcha = new Captcha();
console.log(captcha.value);
 

const path = require("path"),
    fs = require("fs")
 
client.on('message', async message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/);

    const command = args.shift().toLowerCase();

    if (command === 'verification') {
 
            let captcha = new Captcha();
            message.channel.send(
                "**Enter the text shown in the image below:**",
                new Discord.MessageAttachment(captcha.JPEGStream, "captcha.jpeg")
            );
            let collector = message.channel.createMessageCollector(m => m.author.id === message.author.id);
            collector.on("collect", m => {
                if (m.content.toUpperCase() === captcha.value){ message.channel.send("Verified Successfully!");
                let role = message.guild.roles.cache.find(r => r.id === "Verified");
                message.author.roles.add(role);
                }else{ message.channel.send("Failed Verification!");}
                collector.stop();
    });
        

    }
});
        

client.login('you don't need this.');

Any help is appreciated! ^^

Error:

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I see two problems in your code.

  1. message.author refers to an user, which does not hold roles. Use message.member instead

  2. Replace r.id with r.name, id is not a string.

Have a great day :)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda