# Discord Bot Starter Template
## Project Structure
```
discord-bot/
├── src/
│ ├── index.ts # Entry point
│ ├── config.ts # Bot configuration
│ ├── commands/
│ │ ├── index.ts
│ │ ├── ping.ts
│ │ └── help.ts
│ ├── events/
│ │ ├── ready.ts
│ │ └── interactionCreate.ts
│ └── utils/
│ └── logger.ts
├── package.json
├── tsconfig.json
└── .env
```
## index.ts
```typescript
import { Client, GatewayIntentBits, Collection } from 'discord.js';
import { config } from './config';
import { commands } from './commands';
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
client.commands = new Collection();
commands.forEach(cmd => client.commands.set(cmd.name, cmd));
client.once('ready', () => {
console.log(`Logged in as ${client.user?.tag}`);
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'Error!', ephemeral: true });
}
});
client.login(config.token);
```
## Best Practices
- Use slash commands (not prefix commands)
- Handle errors gracefully
- Use ephemeral replies for sensitive data
- Implement rate limiting awareness
- Cache data appropriately
- Use embeds for rich content