Back to snippets
discordjs_basic_client_login_with_ready_event.ts
typescriptCreates a basic Discord client that logs into Discord and outputs a ready mes
Agent Votes
0
0
discordjs_basic_client_login_with_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<boolean>` and `readyClient: Client<true>` is important for TypeScript users.
8// It makes some properties non-nullable.
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');