close
close

discord bot code verification problem

discord bot code verification problem

guys i have a problem with my code can someone help me???

const { Client, GatewayIntentBits, MessageEmbed } = require(‘discord.js’);
const client = new Client({
intentions : (
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.Message content,
GatewayIntentBits.GuildMessageReactions
)
});

const MESSAGE_ID = ‘1271814120345178152’; // The ID of the message that users should react to
const VERIFY_ROLE_NAME = ‘verify’; // Name of the role to assign
const VERIFY_EMOJI = ‘✅’; // Verification emoji

client.once(‘ready’, () => {
console.log(‘My BOT is connected’);
});

client.on(‘messageCreate’, async(message) => {
// Check if the message is the one from the command
if (message.content === “to be able to see all the rooms please reply with an emoji”) {
const embed = new MessageEmbed()
.setColor(“GREEN”)
.setTitle(‘React to get the role!’)
.setDescription(‘React with “✅” to get the “verify” role.’);

    const messageEmbed = await message.channel.send({ embeds:  });
    messageEmbed.react(VERIFY_EMOJI);
}
Enter full screen mode

Exit full screen mode

});

client.on(‘messageReactionAdd’, async (reaction, user) => {
if (reaction.message.partial) wait for reaction.message.fetch();
if (reaction.partial) wait reaction.fetch();
if (user.bot) returns ;
if (!reaction.message.guild) returns ;

if (reaction.message.id === MESSAGE_ID && reaction.emoji.name === VERIFY_EMOJI) {
    try {
        const guild = reaction.message.guild;
        const member = await guild.members.fetch(user.id);
        const role = guild.roles.cache.find(r => r.name === VERIFY_ROLE_NAME);

        if (role) {
            await member.roles.add(role);
            console.log(`Rôle '${VERIFY_ROLE_NAME}' attribué à ${user.tag}`);
        } else {
            console.log("Rôle introuvable.");
        }
    } catch (err) {
        console.error('Erreur lors de l\'attribution du rôle:', err);
    }
}
Enter full screen mode

Exit full screen mode

});