Search code examples
embedmessagevote

Discord.js V12 Vote command not working somehow


so I am working on a command that makes like a vote embed, and it doesn't really work. when I use (in my case) $repvote @user it doesn't recognize the user or anything.., let me know for any solutions!

    if (message.author.bot) return;
    if (message.content.startsWith(prefix + "repvote")) {
        if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send('You do not have that permission! :x:').then(message.react('❌'));
        let repUser = message.mentions.members.first()
        if(!repUser) return message.channel.send("Please mention the user you want to setup the vote for!").then(message.react('❌')).then(msg => { msg.delete({ timeout: 5000 });
         
        const repVoteEmbed = new Discord.MessageEmbed()
        
        repVoteEmbed.setTitle("Vote for Representative Members :crown:")
        repVoteEmbed.setDescription(`User ${repUser} wants to recieve Representative Members :crown: role! Do you agree?`)
        repVoteEmbed.setFooter(`Vote by: ${message.author.tag}, started on : ${message.createdAt}`)
        message.channel.send({repVoteEmbed}).then(message.react('✔')).then(message.react('❌'))
    })
}})```

Solution

  • You missing message.channel.send(embed).then(msg =>....

    Message channel send return a promise of the sent message, so you need use it to react

    const Discord = require('discord.js');
    const bot = new Discord.Client();
    bot.on('message', async (message) => {
        if (message.author.bot) return;
        if (message.content.startsWith(prefix + 'repvote')) {
            if (!message.member.hasPermission('MANAGE_ROLES')) return message.channel.send('You do not have that permission! :x:').then(message.react('❌'));
            let repUser = message.mentions.members.first();
            if (!repUser) {
                 message.channel.send('Please mention the user you want to setup the vote for!').then((declineMsg) => {
                    message.react('❌');
                    declineMsg.delete({
                        timeout: 5000,
                    });
                });
                 return;
            }
            const repVoteEmbed = new Discord.MessageEmbed();
            repVoteEmbed.setTitle('Vote for Representative Members :crown:');
            repVoteEmbed.setDescription(`User ${repUser} wants to recieve Representative Members :crown: role! Do you agree?`);
            repVoteEmbed.setFooter(`Vote by: ${message.author.tag}, started on : ${message.createdAt}`);
            message.channel.send(repVoteEmbed).then((msg) => {
                msg.react(`✔`).then(() => msg.react('❌'));
            });
        }
    });