This commit is contained in:
yhqe committed 2026-03-12 18:38:28 -05:00
1 parent 238dce1738
commit 9f9c852a36
1 file changed
+41 -40
+41 -40
View File
@@ -1,43 +1,43 @@
# twitter_v3 — Discord Moderation Bot # twitter_v3 — discord moderation bot
A Discord.js **v14** bot base using traditional **prefix commands** (no slash commands) and structured **Winston logging**. a discord.js v14 bot base using traditional prefix commands (no slash commands) and structured winston logging.
--- ---
## Features ## features
- 📨 **Prefix command system** — commands triggered by a configurable prefix (default `!`) - prefix command system — commands triggered by a configurable prefix (default `!`)
- 📁 **Auto-loading** — commands and events are loaded automatically from their folders - auto-loading — commands and events are loaded automatically from their folders
- 🔖 **Aliases** — each command can define one or more aliases - aliases — each command can define one or more aliases
- 📝 **Winston logging** — coloured console output + rolling log files (`logs/combined.log`, `logs/error.log`) - winston logging — coloured console output + rolling log files (`logs/combined.log`, `logs/error.log`)
- 🛡️ **Global error handling** — unhandled rejections and uncaught exceptions are caught and logged - global error handling — unhandled rejections and uncaught exceptions are caught and logged
--- ---
## Project Structure ## project structure
``` ```
src/ src/
├── index.js # Entry point — creates the client, loads handlers ├── index.js # entry point — creates the client, loads handlers
├── commands/ ├── commands/
│ ├── help.js # !help — lists commands or shows command detail │ ├── help.js # !help — lists commands or shows command detail
│ └── ping.js # !ping — latency check │ └── ping.js # !ping — latency check
├── events/ ├── events/
│ ├── ready.js # Fires once when the bot is online │ ├── ready.js # fires once when the bot is online
│ └── messageCreate.js # Parses every message for prefix commands │ └── messageCreate.js # parses every message for prefix commands
├── handlers/ ├── handlers/
│ ├── commandHandler.js # Reads src/commands/ and registers commands │ ├── commandHandler.js # reads src/commands/ and registers commands
│ └── eventHandler.js # Reads src/events/ and registers Discord events │ └── eventHandler.js # reads src/events/ and registers discord events
└── utils/ └── utils/
└── logger.js # Winston logger instance └── logger.js # winston logger instance
logs/ # Created automatically at runtime (git-ignored) logs/ # created automatically at runtime (git-ignored)
``` ```
--- ---
## Setup ## setup
### 1. Clone & install dependencies ### 1. clone & install dependencies
```bash ```bash
git clone https://github.com/yhqe/twitter_v3.git git clone https://github.com/yhqe/twitter_v3.git
@@ -45,58 +45,58 @@ cd twitter_v3
npm install npm install
``` ```
### 2. Configure environment variables ### 2. configure environment variables
```bash ```bash
cp .env.example .env cp .env.example .env
``` ```
Open `.env` and fill in: open `.env` and fill in:
| Variable | Required | Description | | variable | required | description |
|-------------|----------|------------------------------------------------------| |-------------|----------|------------------------------------------------------|
| `BOT_TOKEN` | ✅ Yes | Your bot token from the Discord Developer Portal | | `BOT_TOKEN` | yes | your bot token from the discord developer portal |
| `PREFIX` | ❌ No | Command prefix (default: `!`) | | `PREFIX` | no | command prefix (default: `!`) |
| `GUILD_ID` | ❌ No | Test server ID (handy for dev utilities) | | `GUILD_ID` | no | test server id (handy for dev stuff) |
### 3. Enable the Message Content intent ### 3. enable the message content intent
Go to your application in the [Discord Developer Portal](https://discord.com/developers/applications), open **Bot → Privileged Gateway Intents**, and enable **Message Content Intent**. This is required for prefix commands. go to your application in the [discord developer portal](https://discord.com/developers/applications), open **bot → privileged gateway intents**, and enable **message content intent**. you need this for prefix commands.
### 4. Start the bot ### 4. start the bot
```bash ```bash
# Production # production
npm start npm start
# Development (auto-restarts on file changes, Node.js 18+) # development (auto-restarts on file changes, node.js 18+)
npm run dev npm run dev
``` ```
--- ---
## Adding Commands ## adding commands
Create a file in `src/commands/`. The handler will load it automatically on next start. create a file in `src/commands/`. the handler will load it automatically on next start.
```js ```js
'use strict'; 'use strict';
module.exports = { module.exports = {
name: 'example', // Primary command name (also used as the key) name: 'example', // primary command name (also used as the key)
description: 'An example command.', description: 'An example command.',
aliases: ['ex'], // Optional aliases aliases: ['ex'], // optional aliases
usage: 'example <text>', // Shown in !help example usage: 'example <text>', // shown in !help example
async execute(client, message, args) { async execute(client, message, args) {
await message.reply(`You said: ${args.join(' ')}`); await message.reply(`You said: ${args.join(' ')}`);
}, },
}; };
``` ```
## Adding Events ## adding events
Create a file in `src/events/`. Set `once: true` if it should fire only once (e.g. `ready`). create a file in `src/events/`. set `once: true` if it should fire only once (e.g. `ready`).
```js ```js
'use strict'; 'use strict';
@@ -107,14 +107,15 @@ module.exports = {
name: Events.GuildMemberAdd, name: Events.GuildMemberAdd,
async execute(client, member) { async execute(client, member) {
console.log(`${member.user.tag} joined ${member.guild.name}`); console.log(`${member.user.tag} joined ${member.guild.name}`);
}, },
}; };
``` ```
--- ---
## Logging ## logging
log files are written to the `logs/` directory (git-ignored). the log level defaults to `info` and can be overridden with the `LOG_LEVEL` environment variable (e.g. `LOG_LEVEL=debug npm start`).
Log files are written to the `logs/` directory (git-ignored). The log level defaults to `info` and can be overridden with the `LOG_LEVEL` environment variable (e.g. `LOG_LEVEL=debug npm start`).