logo

Constatic

Discord Bot BaseConventions

Intents

Bot intents

Intents were introduced by Discord so that bot developers can choose which events their bot receives based on what data it needs to function. In order for a given event to be emitted, a related intent needs to be enabled.

For example, one of the most used events in Discord bots is guildMemberAdd, this event is emitted when a member joins the guild, but it is necessary to set the GuildMembers intent for the event to be emitted.

When generating this project, by default all intents are enabled in the Client. See below what a simple code would look like without using Constatic Base:

src/index.ts
import { Client } from "discord.js";
 
const client = new Client({ 
    intents: [
        "GuildMembers",
        "MessageContent",
        "Guilds",
        "GuildBans",
        "GuildPresences",
        // ...
    ]
});

But it is not necessary to set any intent, because by default, they are all already enabled:

src/index.ts
import { bootstrap } from "#base";
 
await bootstrap({ meta: import.meta });

However, if you want to set only specific intents, as in the case of a public bot where you do not want to enable the MessageContent intent, simply use the intents property of the bootstrap function, it is the same as the Client options:

src/index.ts
import { bootstrap } from "#base";
 
await bootstrap({ 
    meta: import.meta,
    intents: [
        "Guilds",
        "GuildWebhooks",
        "GuildBans",
        // ...
    ]    
});

On this page

No Headings