Reputation: 25
I am trying to make emoji reaction for my discord bot , everything is okay until I click "❌" emoji but when i click "❌" emoji i am getting this error: TypeError: Cannot read property 'emoji' of undefined
and the error shows this line : if (reaction.emoji.name === '❌')
const Discord = require("discord.js");
const ayarlar = require("../ayarlar.json");
module.exports.run = async (bot, message, args) => {
let gonderenKisi = message.author;
let mesaj = args.slice(0).join(" ");
if(!mesaj) return message.reply("**➤ Mesaj Atabilmek İçin Bir Mesaj Yazmalısın!**").then(message => {
message.delete({ timeout: 5000 });
});
const filter = (reaction, user) => {
return ['❌'].includes(reaction.emoji.name) && user.id === message.author.id;
};
const sEmbed = new Discord.MessageEmbed()
.setDescription(`➤ ` + mesaj)
.setAuthor(`➤ Yeni Bir Fotoğraf Paylaşıldı !`)
.setThumbnail(message.guild.iconURL())
.setColor('RANDOM')
.setFooter(`➤ Fotoğraf Atan: ${message.author.username}`, message.author.displayAvatarURL())
.setTimestamp(message.createdAt)
message.delete();
message.channel.send(sEmbed).then(e =>
e.react("❤️")).then(e =>
e.message.react("❌")).catch(e => {
console.error('Emojiler De Sorun Var.');
});
message.awaitReactions(filter, { max: 1 })
.then(collected => {
const reaction = collected.first();
if (reaction.emoji.name === '❌') {
collected.on('collect', () => {
message.delete();
var s2Embed = new Discord.MessageEmbed()
.setTitle(`${message.author.username} Mesajın Silindi.`)
.setColor('RANDOM')
.setDescription(`Mesajı Silen : ${message.author.username}`, message.author.displayAvatarURL())
message.channel.send(s2Embed)
});
}
}).catch(e => {
console.error(e)
})
};
module.exports.config = {
name: 'instagram',
aliases: ['i']
}
Upvotes: 1
Views: 1408
Reputation: 388
The actual cause of the error is this line:
const reaction = collected.first();
Here the value of reaction is undefined so you are getting the error.You are trying to read the emoji property of an undefined value.You can change the condition to:
if (reaction && reaction.emoji && reaction.emoji.name){
////logic
}
Also I can see there is some issue in the discord version probably which is giving you an undefined value. Check this thread it may help you.
Upvotes: 1