Developer
Events
Ready Event

Ready Event

The ready event in Discord.js is a crucial event that signifies when the bot has successfully connected to Discord and is ready to start receiving and responding to events. This event is triggered once, immediately after the bot logs in and establishes a connection with Discord's servers.

Project Structure

First, create a folder named events inside the src folder. Then create a client folder inside the events folder and add a file named ready.ts.

        • ready.ts
  • Create ready.ts

    Now we will write the logic for the ready event.

    src/events/client/ready.ts
    import { logPastelPink } from 'nstypocolors'
    import { ExtendedClient } from '../../interfaces/ExtendedClient'
    import { ActivityType } from 'discord.js'
    import { BOT } from '../../configs/metadata'
     
    export const registerReadyEvent = (client: ExtendedClient) => {
      client.once('ready', () => {
        logPastelPink(`Successfully connected both Message & Slash clients ${client.user?.tag}!`)
     
        client.user?.setPresence({
          activities: [
            {
              name: `${BOT.PREFIX}help • ${client.user?.username}`,
              type: ActivityType.Custom,
            },
          ],
          status: 'online',
        })
      })
    }

    You can customize this as you want. For more information, please visit the Discord.js (opens in a new tab) official documentation about the ready event and its types.

    Required Dependencies

    For this, you may have noticed that we have used the color library nstypocolors. Install nstypocolors via npm (opens in a new tab)

    npm i nstypocolors
    ⚠️

    We are highly suggested you to use nstypocolors only, dont use any other color libraries.

    Alright, we have done it! Now let's move ahead.