Browse Source

Fix messageDelete and improve messageUpdate logs

master
Abheek Dhawan 4 years ago
parent
commit
a124e2c7eb
  1. 55
      bot.js

55
bot.js

@ -657,32 +657,29 @@ async function bulkDelete(message) {
}).catch(console.error); }).catch(console.error);
} }
client.on('messageDelete', msg => { client.on('messageDelete', message => {
msg.channel.messages.fetch(msg.id) const deleteEmbed = new Discord.MessageEmbed()
.then(message => { .setTitle('Message Deleted')
const deleteEmbed = new Discord.MessageEmbed() .setURL(message.url)
.setTitle('Message Deleted') .setAuthor(message.author ? message.author.tag : "Unknown", message.author ? message.author.avatarURL() : client.user.defaultAvatarURL)
.setAuthor(message.author.tag, message.author.avatarURL()) .addField('Author', message.author ? message.author.tag : "Message not cached")
.setURL(message.url) .addField('Message', message.content ? message.content : "Message not cached")
.addField('Author', message.author.tag) .setThumbnail(message.author.avatarURL())
.addField('Message', message.content) .setFooter("ID: " + message.id)
.setThumbnail(message.author.avatarURL()) .setTimestamp()
.setFooter("ID: " + message.id) .setColor('e7778b');
.setTimestamp()
.setColor('e7778b');
collection.findOne({ guild_id: message.guild.id }, (error, result) => { collection.findOne({ guild_id: message.guild.id }, (error, result) => {
if (error) { if (error) {
console.error; console.error;
} }
if (result.bot_logs_id) { if (result.bot_logs_id) {
botLogsChannel = result.bot_logs_id; botLogsChannel = result.bot_logs_id;
if (message.guild.channels.cache.get(botLogsChannel)) { if (message.guild.channels.cache.get(botLogsChannel)) {
message.guild.channels.cache.get(botLogsChannel).send(deleteEmbed).catch(console.error); message.guild.channels.cache.get(botLogsChannel).send(deleteEmbed).catch(console.error);
} }
} }
}); });
});
}); });
client.on('messageDeleteBulk', messages => { client.on('messageDeleteBulk', messages => {
@ -709,10 +706,8 @@ client.on('messageDeleteBulk', messages => {
}); });
client.on('messageUpdate', (originalMessage, editedMessage) => { client.on('messageUpdate', (originalMessage, editedMessage) => {
if (editedMessage.author) { message.channel.messages.fetch(editedMessage.id)
if (editedMessage.author.bot) { .then(editedMessage => {
return;
}
const editEmbed = new Discord.MessageEmbed() const editEmbed = new Discord.MessageEmbed()
.setTitle("Message Edited") .setTitle("Message Edited")
.setURL(editedMessage.url) .setURL(editedMessage.url)
@ -733,7 +728,7 @@ client.on('messageUpdate', (originalMessage, editedMessage) => {
} }
} }
}); });
} });
}); });
client.on('channelCreate', channel => { client.on('channelCreate', channel => {

Loading…
Cancel
Save