'How do I make a discord bot send a message upon joining

I am new to JavaScript and I am trying to figure out how to make a Discord Bot send a message every time it joins a new server. Can someone explain to me how to do this and the logic behind the code?



Solution 1:[1]

You should read the docs for this: https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-guildCreate

bot.on('guildCreate', (guild) => {
    guild.systemChannel.send("I have joined the server!");
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RyloRiz