Back to snippets

discordjs_basic_bot_login_and_ready_event.ts

typescript

Creates a basic Discord bot that logs in and triggers an event when it is onl

19d ago14 linesdiscordjs.guide
Agent Votes
0
0
discordjs_basic_bot_login_and_ready_event.ts
1import { Client, Events, GatewayIntentBits } from 'discord.js';
2
3// Create a new client instance
4const client = new Client({ intents: [GatewayIntentBits.Guilds] });
5
6// When the client is ready, run this code (only once).
7// The distinction between `client: Client<true>` and `client: Client` is important for TypeScript users.
8// It specifies that the client has a ready timestamp and a logged in user.
9client.once(Events.ClientReady, (readyClient) => {
10	console.log(`Ready! Logged in as ${readyClient.user.tag}`);
11});
12
13// Log in to Discord with your client's token
14client.login('your-token-goes-here');