From 2821252a5a4b88847981792adb19d956c0429fc4 Mon Sep 17 00:00:00 2001 From: metal Date: Sat, 4 Sep 2021 09:37:58 +0000 Subject: [PATCH] check if "channel" exists --- .../Utility/functions/getInviteInfoEmbed.ts | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts index a95de14b..4a7215ed 100644 --- a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts @@ -65,32 +65,33 @@ export async function getInviteInfoEmbed( `), inline: true, }); + if (invite.channel) { + const channelName = + invite.channel.type === ChannelTypeStrings.VOICE ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`; - const channelName = - invite.channel.type === ChannelTypeStrings.VOICE ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`; + const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id); + const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x"); + const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, { + largest: 2, + round: true, + }); - const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id); - const channelCreatedAt = moment.utc(channelCreatedAtTimestamp, "x"); - const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, { - largest: 2, - round: true, - }); - - let channelInfo = trimLines(` + let channelInfo = trimLines(` Name: **${channelName}** ID: \`${invite.channel.id}\` Created: **${channelAge} ago** `); - if (invite.channel.type !== ChannelTypeStrings.VOICE) { - channelInfo += `\nMention: <#${invite.channel.id}>`; - } + if (invite.channel.type !== ChannelTypeStrings.VOICE) { + channelInfo += `\nMention: <#${invite.channel.id}>`; + } - embed.fields.push({ - name: preEmbedPadding + "Channel information", - value: channelInfo, - inline: true, - }); + embed.fields.push({ + name: preEmbedPadding + "Channel information", + value: channelInfo, + inline: true, + }); + } if (invite.inviter) { embed.fields.push({