Ad2017
Ad2017

Reputation: 19

Is there a way to check if discord bot joins a server?

I'm making a discord bot and I want to check if it joins a server so I can set prefixes, send messages etc.
I tried searching for this but I didn't find anything that could help.

I thought it could be an event so tried something like:

client.on('join_guild', (guild) => {
    prefix = "!"
});

But, of course, it didn't work.

Is there something like the code shown above?

Upvotes: 1

Views: 3731

Answers (1)

T. Dirks
T. Dirks

Reputation: 3676

I think you're looking for the guildCreate event. It gets triggered once your bot joins a new guild. Example code:

client.on("guildCreate", (guild) => {
    // This event triggers when the bot joins a guild.    
    console.log(`Joined new guild: ${guild.name}`);
});

Upvotes: 2

Related Questions