I tried to make a confirmation system by awaiting a reaction from this user, for some reason, I can’t get it to work.
Here is the code:
if (command === 'reset') { if (!msg.member.hasPermission('MANAGE_SERVER')) msg.reply('You need `Mannage server` permission to delete the progress.'); //checking if author has mangage server permissions. msg.channel .send('Are you sure you want to delete all your progress?') .then((message) => { message.react('✅').then(() => message.react('❌')); }); //confirming if author wants to delete channel. const filter = (reaction, user) => { return ( ['✅', '❌'].includes(reaction.emoji.name) && user.id === msg.author.id ); }; const fetchedChannel = msg.guild.channels.cache.find( (channel) => channel.name === 'counting' ); //getting the channel msg .awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }) .then((collected) => { const reaction = collected.first(); if (reaction.emoji.name === '✅') { fetchedChannel.delete(); msg.reply('Deleted all progress. to start over, run ".init"'); } else { msg.reply('Aborting missing.'); return; } }) .catch((collected) => { msg.reply('No response given.'); }); }
If anyone could help, it would be great! Thanks.
Advertisement
Answer
I was reviewing your code and I think I fixed it since I have tried this and it worked as expected. The explanation of what I did is in the code (line 19). If you have any questions or still having problems with the code, I’ll be glad to help. Happy coding
if (command === 'reset') { if (!msg.member.hasPermission('MANAGE_SERVER')) return msg.reply( 'You need `Mannage server` permission to delete the progress.' ); // You forgot to add a return to prevent the command from people without enough permissions msg.channel .send('Are you sure you want to delete all your progress?') .then((message) => { message.react('✅'); message.react('❌'); // I removed a .then(...) //confirming if author wants to delete channel. const filter = (reaction, user) => { return ( ['✅', '❌'].includes(reaction.emoji.name) && user.id === msg.author.id ); }; const fetchedChannel = msg.guild.channels.cache.find( (channel) => channel.name === 'counting' ); //getting the channel message .awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] }) // The problem was in this line, you used "msg" instead of "message", it means the bot wasn't awaiting reactions of its own message, it was awaiting reactions from the author's message. .then((collected) => { const reaction = collected.first(); if (reaction.emoji.name === '✅') { fetchedChannel.delete(); msg.reply('Deleted all progress. to start over, run ".init"'); } else { msg.reply('Aborting missing.'); return; } }) .catch((collected) => { msg.reply('No response given.'); }); }); }