node.js – discord.js how to send message when bot joins to a new server without system message channel?

I’m trying to send message with bot upon joining with statement.

//Will post message when bot joined new server because system channel exists.
if(guild.systemChannelId != null) return guild.systemChannel.send("Thank you for invite!"), console.log('Bot Joined new server!') 
//Send post join message when there is no system channel on the server to possible channel (not working)
      client.guilds.cache.forEach((channel) => {
        if(channel.type == "text") {
            if(channel.permissionsFor(guild.me).has("SEND_MESSAGES")) {
         channel.send("Thanks for inviting me")
        console.log('Bot Joined new server!')
          }
        }
      })
guild.systemChannel.send("Thank you for invite!")

This one works and will send message to the “default system channel”. Problem is if server has no system channel, this will appear as error. So i had to create statement above and use this request only when default channel exists.

Error: Unhandled rejection TypeError: Cannot read property 'send' of null -> error will appear when using only guild.systemChannel.send("Thank you for invite!") in the code without statement.

How to send message to the first channel possible if default channel does not exist on the server?