From 746ae2e56dc87a3a25ffb26bbe8975058fc3a585 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 31 Mar 2021 15:08:01 -0500 Subject: [PATCH] Fix null errors for message deletes --- index.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d16cba3..b30daba 100644 --- a/index.js +++ b/index.js @@ -18,12 +18,21 @@ client.on("guildMemberAdd", member => { }); client.on('messageDelete', message => { + const messageContent = message.content; + const messageAvatar = message.author.avatarURL(); + const messageID = message.id; + let messageAuthor; + if (message.author) { + messageAuthor = message.author.tag; + } else { + messageAuthor = "Someone else deleted this message" + } const deleteEmbed = new Discord.MessageEmbed() .setTitle('Message Deleted') - .addField('Author', message.author.tag) - .addField('Message', message.content) - .setThumbnail(message.author.avatarURL()) - .setFooter("ID: " + message.id) + .addField('Author', messageAuthor) + .addField('Message', messageContent) + .setThumbnail(messageAvatar) + .setFooter("ID: " + messageID) .setTimestamp() .setColor('ff0000'); client.guilds.cache.get("826506878976000030").channels.cache.get("826876551756513314").send(deleteEmbed).catch(console.error); @@ -48,6 +57,7 @@ client.on('channelCreate', channel => { if (channel.guild.id = "826506878976000030") { const channelName = channel.name; const channelID = channel.id; + const channelType = channel.type; let channelCategory; if (channel.parent) { channelCategory = channel.parent.name; @@ -55,8 +65,9 @@ client.on('channelCreate', channel => { channelCategory = "None"; } const channelCreateEmbed = new Discord.MessageEmbed() - .setTitle("#️⃣Channel Created") + .setTitle("Channel Created") .addField("Name", channelName) + .addField("Type", channelType) .addField("Category", channelCategory) .setFooter("ID: " + channelID) .setTimestamp()