N
N
Nikita Kudrin2020-09-04 07:47:34
JavaScript
Nikita Kudrin, 2020-09-04 07:47:34

The code is not working correctly. How to fix?

Wrote a small code to confirm actions.

client.on('message', message => {
    if(message.author === client.user) return;
    if(message.channel.name == 'bot_test') {
const exampleEmbed = new Discord.MessageEmbed()
  .setColor('#0099ff')
  .setTitle('Подтверждение действия')
  .setDescription(`Вополняемое действие: **${message.content}**\nПользователь: <@${message.author.id}> `)
  .addFields(
    { name: '✅ - Подтвердить', value: 'При нажатии на реакцию действие подтверждается'},
    { name: '❓ - Подробнее', value: 'При нажатии на реакцию вам в личные сообщения будет отправлено сообщение с описанием действия'},
    { name: '❎ - Отменить', value: 'При нажатии на реакцию действие отменяетмя и сообщение бота удаляется'},
                { name: '**У Вас есть ровно 30 секунд на подтверждение**', value: '\u200B'},
  )
  .setTimestamp()
  .setFooter('Ferrera Family Bot', 'https://i.imgur.com/YDVgOgw.png');
message.channel.send(exampleEmbed)
await message.react('✅');
const filter = (reaction, user) => reaction.emoji.name === '✅' && user.id == message.author.id 
const collector = message.createReactionCollector(filter, { time: 15000 });
collector.on('collect', r => message.reply(`Сообщение #1`));
collector.on('end', collected => message.reply(`Сообщение #2`));
message.delete();
}
});

So, for some reason, he does not wait for 15 seconds, but immediately sends "Message # 2"
And when you click on the reaction, nothing happens.
Help, what did I do wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-09-04
@HepkaPlay

some code you have is too confusing, why don't you use the one I suggested in the previous question?
why, where , you specify only one parameter, if the bot should collect not only the reaction, but also the user? why are you using the method , apart from the sent messages? how does the bot know which one to delete? used for such purposescollector.on("collect", r => . . .)
.delete()

.then(message => {
. . .
})

in addition, starting from v12 discord.js and higher, inside the brackets .delete(), the time after which the message must be deleted is indicated{ timeout: время_в_миллисекундах }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question