vcord.js 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/docs/README.md +48 -0
- package/docs/advanced.md +347 -0
- package/docs/builders.md +136 -0
- package/docs/client.md +153 -0
- package/docs/commands.md +178 -0
- package/docs/events.md +250 -0
- package/docs/getting-started.md +243 -0
- package/docs/structures.md +198 -0
- package/example/.env.example +10 -0
- package/example/README.md +142 -0
- package/example/cogs/ExampleCog.js +191 -0
- package/example/cogs/errorHandling.js +126 -0
- package/example/cogs/moderation.js +237 -0
- package/example/cogs/utilities.js +100 -0
- package/example/decorators-example.js +158 -0
- package/example/example.js +254 -0
- package/example/index.js +104 -0
- package/example/utils/cogLoader.js +76 -0
- package/package.json +27 -7
- package/vcord/client/Client.js +602 -9
- package/vcord/client/builders/ComponentBuilder.js +236 -0
- package/vcord/client/builders/EmbedBuilder.js +110 -0
- package/vcord/client/builders/SlashCommandBuilder.js +384 -0
- package/vcord/client/decorators/Decorators.js +242 -0
- package/vcord/client/decorators/index.js +304 -0
- package/vcord/client/extentions/ApiHandler.js +421 -39
- package/vcord/client/extentions/BaseClient.js +58 -18
- package/vcord/client/extentions/EmbedBuilder.js +110 -0
- package/vcord/client/extentions/WsHandler.js +266 -19
- package/vcord/client/extentions/config.js +178 -2
- package/vcord/client/extentions/intents.js +31 -2
- package/vcord/client/structures/Channel.js +21 -0
- package/vcord/client/structures/Cog.js +114 -0
- package/vcord/client/structures/Guild.js +157 -0
- package/vcord/client/structures/GuildMember.js +118 -0
- package/vcord/client/structures/Interaction.js +297 -0
- package/vcord/client/structures/Message.js +150 -0
- package/vcord/client/structures/Role.js +93 -0
- package/vcord/client/structures/User.js +107 -0
- package/vcord/core/actions/ActionManager.js +205 -0
- package/vcord/core/cache/CacheManager.js +213 -0
- package/vcord/core/client/Base.js +109 -0
- package/vcord/core/client/Client.js +141 -0
- package/vcord/core/rest/RESTManager.js +216 -0
- package/vcord/core/ws/WebSocketManager.js +253 -0
- package/vcord/decorators/errorHandler.js +110 -0
- package/vcord/decorators/errors/handler.js +74 -0
- package/vcord/decorators/errors/handlers.js +68 -0
- package/vcord/decorators/errors/index.js +9 -0
- package/vcord/errors/base.js +18 -0
- package/vcord/errors/commands.js +38 -0
- package/vcord/errors/context.js +43 -0
- package/vcord/errors/index.js +15 -0
- package/vcord/errors/input.js +52 -0
- package/vcord/errors/permissions.js +54 -0
- package/vcord/errors/ratelimit.js +35 -0
- package/vcord/index.js +79 -1
- package/vcord/structures/Base.js +66 -0
- package/vcord/structures/Channel.js +337 -0
- package/vcord/structures/ClientUser.js +81 -0
- package/vcord/structures/Guild.js +369 -0
- package/vcord/structures/GuildMember.js +243 -0
- package/vcord/structures/Interaction.js +250 -0
- package/vcord/structures/Message.js +312 -0
- package/vcord/structures/Role.js +232 -0
- package/vcord/structures/User.js +200 -0
- package/vcord/utils/Collection.js +173 -0
- package/vcord/utils/Constants.js +170 -0
- package/vcord/utils/Snowflake.js +71 -0
- package/vcord/vord.js +159 -0
package/README.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# vcord
|
2
|
+
|
3
|
+
A modern, user-friendly Discord bot library built on top of Discord.js, designed to simplify bot development while maintaining powerful functionality.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- 🚀 Simplified API for common Discord bot operations
|
8
|
+
- 📝 Intuitive message handling and manipulation
|
9
|
+
- 🎨 Easy-to-use Embed builder
|
10
|
+
- 🔧 Custom channel management system
|
11
|
+
- 🛠️ Built-in utilities for common bot tasks
|
12
|
+
- 🔄 Promise-based API for modern async/await usage
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
```bash
|
17
|
+
npm install vcord
|
18
|
+
```
|
19
|
+
|
20
|
+
## Quick Start
|
21
|
+
|
22
|
+
```javascript
|
23
|
+
const { Client, EmbedBuilder } = require('vcord');
|
24
|
+
|
25
|
+
const client = new Client({
|
26
|
+
intents: ['GUILDS', 'GUILD_MESSAGES', 'MESSAGE_CONTENT']
|
27
|
+
});
|
28
|
+
|
29
|
+
client.on('ready', () => {
|
30
|
+
console.log(`Logged in as ${client.user.username}`);
|
31
|
+
});
|
32
|
+
|
33
|
+
client.on('messageCreate', async (message) => {
|
34
|
+
if (message.content === '!ping') {
|
35
|
+
await message.reply('Pong! 🏓');
|
36
|
+
}
|
37
|
+
|
38
|
+
if (message.content === '!embed') {
|
39
|
+
const embed = new EmbedBuilder()
|
40
|
+
.setTitle('Hello World')
|
41
|
+
.setDescription('This is a simple embed!')
|
42
|
+
.setColor('#FF0000');
|
43
|
+
|
44
|
+
// Send embed directly - no need for toJSON()!
|
45
|
+
await message.reply(embed);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
client.login('YOUR_BOT_TOKEN');
|
50
|
+
```
|
51
|
+
|
52
|
+
## Key Features
|
53
|
+
|
54
|
+
### Message Handling
|
55
|
+
|
56
|
+
```javascript
|
57
|
+
// Send a message
|
58
|
+
await channel.send('Hello World!');
|
59
|
+
|
60
|
+
// Reply to a message
|
61
|
+
const reply = await message.reply('This is a reply!');
|
62
|
+
|
63
|
+
// Edit a message
|
64
|
+
await reply.edit('This message has been edited');
|
65
|
+
|
66
|
+
// Delete a message
|
67
|
+
await reply.delete();
|
68
|
+
|
69
|
+
// Add reactions
|
70
|
+
await message.react('👍');
|
71
|
+
|
72
|
+
// Pin/Unpin messages
|
73
|
+
await message.pin();
|
74
|
+
await message.unpin();
|
75
|
+
```
|
76
|
+
|
77
|
+
### Embeds
|
78
|
+
|
79
|
+
```javascript
|
80
|
+
const embed = new EmbedBuilder()
|
81
|
+
.setTitle('My Embed')
|
82
|
+
.setDescription('This is a description')
|
83
|
+
.setColor('#FF0000')
|
84
|
+
.addField('Field Name', 'Field Value')
|
85
|
+
.setFooter('Footer Text')
|
86
|
+
.setTimestamp();
|
87
|
+
|
88
|
+
// Send embed directly - no toJSON() needed!
|
89
|
+
await message.reply(embed);
|
90
|
+
```
|
91
|
+
|
92
|
+
### Custom Channel System
|
93
|
+
|
94
|
+
```javascript
|
95
|
+
// Set up custom channels
|
96
|
+
client.channel('logs', 'LOGS_CHANNEL_ID');
|
97
|
+
client.channel('welcome', 'WELCOME_CHANNEL_ID');
|
98
|
+
|
99
|
+
// Use custom channels
|
100
|
+
const logsChannel = client.channel('logs');
|
101
|
+
if (logsChannel) {
|
102
|
+
await logsChannel.send('This is a log message');
|
103
|
+
}
|
104
|
+
```
|
105
|
+
|
106
|
+
### Presence Management
|
107
|
+
|
108
|
+
```javascript
|
109
|
+
client.setPresence({
|
110
|
+
activities: [{
|
111
|
+
name: 'with vcord',
|
112
|
+
type: 'PLAYING'
|
113
|
+
}],
|
114
|
+
status: 'online'
|
115
|
+
});
|
116
|
+
```
|
117
|
+
|
118
|
+
### Server Management
|
119
|
+
|
120
|
+
```javascript
|
121
|
+
// Create a channel
|
122
|
+
const newChannel = await client.createChannel(guildId, {
|
123
|
+
name: 'new-channel',
|
124
|
+
type: 0, // Text Channel
|
125
|
+
topic: 'Channel topic'
|
126
|
+
});
|
127
|
+
|
128
|
+
// Create a role
|
129
|
+
const newRole = await client.createRole(guildId, {
|
130
|
+
name: 'New Role',
|
131
|
+
color: '#FF0000',
|
132
|
+
mentionable: true
|
133
|
+
});
|
134
|
+
|
135
|
+
// Ban a user
|
136
|
+
await client.ban(guildId, userId, 'Reason for ban');
|
137
|
+
```
|
138
|
+
|
139
|
+
## Error Handling
|
140
|
+
|
141
|
+
The library uses Promise-based error handling:
|
142
|
+
|
143
|
+
```javascript
|
144
|
+
try {
|
145
|
+
await message.reply('Hello!');
|
146
|
+
} catch (error) {
|
147
|
+
console.error('Failed to send message:', error);
|
148
|
+
}
|
149
|
+
```
|
150
|
+
|
151
|
+
## Contributing
|
152
|
+
|
153
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
154
|
+
|
155
|
+
## License
|
156
|
+
|
157
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
package/docs/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# VCord Documentation
|
2
|
+
|
3
|
+
VCord is a powerful and lightweight Discord bot framework for JavaScript. It provides an intuitive API for creating Discord bots with both traditional prefix commands and slash commands.
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
|
7
|
+
1. [Getting Started](./getting-started.md)
|
8
|
+
2. [Client](./client.md)
|
9
|
+
3. [Commands](./commands.md)
|
10
|
+
4. [Structures](./structures.md)
|
11
|
+
5. [Events](./events.md)
|
12
|
+
6. [Builders](./builders.md)
|
13
|
+
7. [Advanced Usage](./advanced.md)
|
14
|
+
|
15
|
+
## Features
|
16
|
+
|
17
|
+
- Easy-to-use command system
|
18
|
+
- Support for both prefix commands and slash commands
|
19
|
+
- Built-in command groups and subcommands
|
20
|
+
- Powerful event handling
|
21
|
+
- Comprehensive structure classes
|
22
|
+
- Efficient WebSocket management
|
23
|
+
- Built-in permission system
|
24
|
+
- Customizable prefix
|
25
|
+
- Type-safe builders for slash commands
|
26
|
+
|
27
|
+
## Quick Example
|
28
|
+
|
29
|
+
```javascript
|
30
|
+
const { Client } = require('vcord');
|
31
|
+
const { Intents } = require('vcord/client/extentions/intents');
|
32
|
+
|
33
|
+
const client = new Client({
|
34
|
+
intents: [
|
35
|
+
Intents.GUILDS,
|
36
|
+
Intents.GUILD_MESSAGES,
|
37
|
+
Intents.MESSAGE_CONTENT
|
38
|
+
]
|
39
|
+
});
|
40
|
+
|
41
|
+
client.on('ready', () => {
|
42
|
+
console.log(`Logged in as ${client.user.tag}!`);
|
43
|
+
});
|
44
|
+
|
45
|
+
client.login('your-token-here');
|
46
|
+
```
|
47
|
+
|
48
|
+
For more detailed information, check out the specific documentation sections listed in the Table of Contents.
|
package/docs/advanced.md
ADDED
@@ -0,0 +1,347 @@
|
|
1
|
+
# Advanced Usage
|
2
|
+
|
3
|
+
This guide covers advanced features and patterns in VCord.
|
4
|
+
|
5
|
+
## Custom Caching
|
6
|
+
|
7
|
+
VCord provides a flexible caching system that you can customize:
|
8
|
+
|
9
|
+
```javascript
|
10
|
+
const { Client, Intents } = require('vcord');
|
11
|
+
|
12
|
+
const client = new Client({
|
13
|
+
intents: [Intents.GUILDS],
|
14
|
+
cacheOptions: {
|
15
|
+
messageLifetime: 3600, // Cache messages for 1 hour
|
16
|
+
userLifetime: 86400, // Cache users for 24 hours
|
17
|
+
maxMessages: 1000, // Maximum messages to cache
|
18
|
+
maxUsers: 10000 // Maximum users to cache
|
19
|
+
}
|
20
|
+
});
|
21
|
+
```
|
22
|
+
|
23
|
+
## Custom Command Handling
|
24
|
+
|
25
|
+
You can create custom command handlers:
|
26
|
+
|
27
|
+
```javascript
|
28
|
+
class CustomCommandHandler {
|
29
|
+
constructor(client) {
|
30
|
+
this.client = client;
|
31
|
+
this.commands = new Map();
|
32
|
+
}
|
33
|
+
|
34
|
+
register(command) {
|
35
|
+
this.commands.set(command.name, command);
|
36
|
+
}
|
37
|
+
|
38
|
+
async handle(message) {
|
39
|
+
const args = message.content.slice(this.client.prefix.length).trim().split(/ +/);
|
40
|
+
const commandName = args.shift().toLowerCase();
|
41
|
+
|
42
|
+
const command = this.commands.get(commandName);
|
43
|
+
if (!command) return;
|
44
|
+
|
45
|
+
try {
|
46
|
+
await command.execute(message, args);
|
47
|
+
} catch (error) {
|
48
|
+
console.error(error);
|
49
|
+
message.reply('An error occurred while executing the command.');
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
```
|
54
|
+
|
55
|
+
## Custom Events
|
56
|
+
|
57
|
+
Create custom events for your bot:
|
58
|
+
|
59
|
+
```javascript
|
60
|
+
class CustomEvents {
|
61
|
+
constructor(client) {
|
62
|
+
this.client = client;
|
63
|
+
}
|
64
|
+
|
65
|
+
// Custom event that fires when a user levels up
|
66
|
+
async emitLevelUp(user, newLevel) {
|
67
|
+
this.client.emit('levelUp', user, newLevel);
|
68
|
+
}
|
69
|
+
|
70
|
+
// Custom event that fires when a guild milestone is reached
|
71
|
+
async emitGuildMilestone(guild, milestone) {
|
72
|
+
this.client.emit('guildMilestone', guild, milestone);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
// Using custom events
|
77
|
+
client.on('levelUp', (user, newLevel) => {
|
78
|
+
console.log(`${user.tag} reached level ${newLevel}!`);
|
79
|
+
});
|
80
|
+
```
|
81
|
+
|
82
|
+
## Advanced Error Handling
|
83
|
+
|
84
|
+
Create a robust error handling system:
|
85
|
+
|
86
|
+
```javascript
|
87
|
+
class ErrorHandler {
|
88
|
+
constructor(client) {
|
89
|
+
this.client = client;
|
90
|
+
this.setupHandlers();
|
91
|
+
}
|
92
|
+
|
93
|
+
setupHandlers() {
|
94
|
+
// Handle Discord-specific errors
|
95
|
+
this.client.on('error', this.handleDiscordError.bind(this));
|
96
|
+
|
97
|
+
// Handle unhandled promise rejections
|
98
|
+
process.on('unhandledRejection', this.handleUnhandledRejection.bind(this));
|
99
|
+
|
100
|
+
// Handle uncaught exceptions
|
101
|
+
process.on('uncaughtException', this.handleUncaughtException.bind(this));
|
102
|
+
}
|
103
|
+
|
104
|
+
async handleDiscordError(error) {
|
105
|
+
console.error('Discord Error:', error);
|
106
|
+
|
107
|
+
// Log to a Discord channel
|
108
|
+
const logChannel = await this.client.channels.fetch('your-log-channel-id');
|
109
|
+
if (logChannel) {
|
110
|
+
await logChannel.send({
|
111
|
+
embeds: [{
|
112
|
+
title: 'Discord Error',
|
113
|
+
description: error.message,
|
114
|
+
color: 0xFF0000,
|
115
|
+
timestamp: new Date()
|
116
|
+
}]
|
117
|
+
});
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
handleUnhandledRejection(error) {
|
122
|
+
console.error('Unhandled Promise Rejection:', error);
|
123
|
+
}
|
124
|
+
|
125
|
+
handleUncaughtException(error) {
|
126
|
+
console.error('Uncaught Exception:', error);
|
127
|
+
// Gracefully shutdown the bot
|
128
|
+
this.client.destroy();
|
129
|
+
process.exit(1);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
```
|
133
|
+
|
134
|
+
## Custom Middleware
|
135
|
+
|
136
|
+
Create middleware for command handling:
|
137
|
+
|
138
|
+
```javascript
|
139
|
+
class MiddlewareManager {
|
140
|
+
constructor() {
|
141
|
+
this.middleware = [];
|
142
|
+
}
|
143
|
+
|
144
|
+
use(fn) {
|
145
|
+
this.middleware.push(fn);
|
146
|
+
}
|
147
|
+
|
148
|
+
async execute(context, next) {
|
149
|
+
let index = -1;
|
150
|
+
|
151
|
+
const runner = async (i) => {
|
152
|
+
if (i <= index) throw new Error('next() called multiple times');
|
153
|
+
index = i;
|
154
|
+
|
155
|
+
const fn = this.middleware[i];
|
156
|
+
if (i === this.middleware.length) fn = next;
|
157
|
+
if (!fn) return;
|
158
|
+
|
159
|
+
await fn(context, () => runner(i + 1));
|
160
|
+
};
|
161
|
+
|
162
|
+
await runner(0);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
// Usage example
|
167
|
+
const middleware = new MiddlewareManager();
|
168
|
+
|
169
|
+
// Add logging middleware
|
170
|
+
middleware.use(async (ctx, next) => {
|
171
|
+
console.log(`Command executed: ${ctx.commandName}`);
|
172
|
+
const start = Date.now();
|
173
|
+
await next();
|
174
|
+
const ms = Date.now() - start;
|
175
|
+
console.log(`Command completed in ${ms}ms`);
|
176
|
+
});
|
177
|
+
|
178
|
+
// Add permission checking middleware
|
179
|
+
middleware.use(async (ctx, next) => {
|
180
|
+
if (!ctx.member.permissions.has('ADMINISTRATOR')) {
|
181
|
+
throw new Error('You need administrator permissions!');
|
182
|
+
}
|
183
|
+
await next();
|
184
|
+
});
|
185
|
+
```
|
186
|
+
|
187
|
+
## Custom Structures
|
188
|
+
|
189
|
+
Extend Discord structures with custom functionality:
|
190
|
+
|
191
|
+
```javascript
|
192
|
+
class CustomGuild {
|
193
|
+
constructor(guild) {
|
194
|
+
this.guild = guild;
|
195
|
+
this.settings = new Map();
|
196
|
+
}
|
197
|
+
|
198
|
+
async loadSettings() {
|
199
|
+
// Load guild settings from database
|
200
|
+
}
|
201
|
+
|
202
|
+
async saveSettings() {
|
203
|
+
// Save guild settings to database
|
204
|
+
}
|
205
|
+
|
206
|
+
async setupAutomod() {
|
207
|
+
// Setup automod rules
|
208
|
+
}
|
209
|
+
|
210
|
+
async createWelcomeChannel() {
|
211
|
+
// Create and setup welcome channel
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
class CustomMessage {
|
216
|
+
constructor(message) {
|
217
|
+
this.message = message;
|
218
|
+
this.parsed = this.parseMessage();
|
219
|
+
}
|
220
|
+
|
221
|
+
parseMessage() {
|
222
|
+
// Custom message parsing logic
|
223
|
+
return {
|
224
|
+
command: this.message.content.split(' ')[0],
|
225
|
+
args: this.message.content.split(' ').slice(1),
|
226
|
+
flags: this.parseFlags(this.message.content)
|
227
|
+
};
|
228
|
+
}
|
229
|
+
|
230
|
+
parseFlags(content) {
|
231
|
+
const flags = {};
|
232
|
+
const regex = /--(\w+)(?:=(\w+))?/g;
|
233
|
+
let match;
|
234
|
+
|
235
|
+
while ((match = regex.exec(content)) !== null) {
|
236
|
+
flags[match[1]] = match[2] || true;
|
237
|
+
}
|
238
|
+
|
239
|
+
return flags;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
```
|
243
|
+
|
244
|
+
## Advanced Slash Command Features
|
245
|
+
|
246
|
+
Create complex slash commands with subcommands and autocomplete:
|
247
|
+
|
248
|
+
```javascript
|
249
|
+
const { SlashCommandBuilder } = require('vcord');
|
250
|
+
|
251
|
+
const command = new SlashCommandBuilder()
|
252
|
+
.setName('manage')
|
253
|
+
.setDescription('Server management commands')
|
254
|
+
.addSubcommandGroup(group =>
|
255
|
+
group
|
256
|
+
.setName('roles')
|
257
|
+
.setDescription('Manage server roles')
|
258
|
+
.addSubcommand(subcommand =>
|
259
|
+
subcommand
|
260
|
+
.setName('create')
|
261
|
+
.setDescription('Create a new role')
|
262
|
+
.addStringOption(option =>
|
263
|
+
option
|
264
|
+
.setName('name')
|
265
|
+
.setDescription('The role name')
|
266
|
+
.setRequired(true)
|
267
|
+
.setAutocomplete(true)
|
268
|
+
)
|
269
|
+
.addStringOption(option =>
|
270
|
+
option
|
271
|
+
.setName('color')
|
272
|
+
.setDescription('The role color')
|
273
|
+
.addChoices(
|
274
|
+
{ name: 'Red', value: '#FF0000' },
|
275
|
+
{ name: 'Blue', value: '#0000FF' },
|
276
|
+
{ name: 'Green', value: '#00FF00' }
|
277
|
+
)
|
278
|
+
)
|
279
|
+
)
|
280
|
+
);
|
281
|
+
|
282
|
+
// Handle autocomplete interactions
|
283
|
+
client.on('interactionCreate', async interaction => {
|
284
|
+
if (!interaction.isAutocomplete()) return;
|
285
|
+
|
286
|
+
if (interaction.commandName === 'manage') {
|
287
|
+
const focusedOption = interaction.options.getFocused(true);
|
288
|
+
if (focusedOption.name === 'name') {
|
289
|
+
const choices = ['Moderator', 'Admin', 'VIP', 'Member']
|
290
|
+
.filter(choice => choice.startsWith(focusedOption.value))
|
291
|
+
.slice(0, 25);
|
292
|
+
|
293
|
+
await interaction.respond(
|
294
|
+
choices.map(choice => ({ name: choice, value: choice }))
|
295
|
+
);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
});
|
299
|
+
```
|
300
|
+
|
301
|
+
## Rate Limiting
|
302
|
+
|
303
|
+
Implement rate limiting for commands:
|
304
|
+
|
305
|
+
```javascript
|
306
|
+
class RateLimiter {
|
307
|
+
constructor() {
|
308
|
+
this.limits = new Map();
|
309
|
+
}
|
310
|
+
|
311
|
+
async checkLimit(key, limit, time) {
|
312
|
+
const now = Date.now();
|
313
|
+
const userLimits = this.limits.get(key) || [];
|
314
|
+
|
315
|
+
// Remove expired timestamps
|
316
|
+
const valid = userLimits.filter(timestamp => now - timestamp < time);
|
317
|
+
|
318
|
+
if (valid.length >= limit) {
|
319
|
+
return false;
|
320
|
+
}
|
321
|
+
|
322
|
+
valid.push(now);
|
323
|
+
this.limits.set(key, valid);
|
324
|
+
return true;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
// Usage in commands
|
329
|
+
const rateLimiter = new RateLimiter();
|
330
|
+
|
331
|
+
client.on('interactionCreate', async interaction => {
|
332
|
+
if (!interaction.isCommand()) return;
|
333
|
+
|
334
|
+
const canExecute = await rateLimiter.checkLimit(
|
335
|
+
interaction.user.id,
|
336
|
+
5, // 5 commands
|
337
|
+
60000 // per minute
|
338
|
+
);
|
339
|
+
|
340
|
+
if (!canExecute) {
|
341
|
+
await interaction.reply('You are being rate limited!');
|
342
|
+
return;
|
343
|
+
}
|
344
|
+
|
345
|
+
// Execute command
|
346
|
+
});
|
347
|
+
```
|
package/docs/builders.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# VCord Builders Documentation
|
2
|
+
|
3
|
+
VCord provides several builder classes to help you create complex Discord objects easily.
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
- [SlashCommandBuilder](#slashcommandbuilder)
|
7
|
+
- [EmbedBuilder](#embedbuilder)
|
8
|
+
- [ComponentBuilder](#componentbuilder)
|
9
|
+
- [ButtonBuilder](#buttonbuilder)
|
10
|
+
- [SelectMenuBuilder](#selectmenubuilder)
|
11
|
+
- [TextInputBuilder](#textinputbuilder)
|
12
|
+
|
13
|
+
## SlashCommandBuilder
|
14
|
+
|
15
|
+
The `SlashCommandBuilder` class helps you create slash commands with proper validation and type checking.
|
16
|
+
|
17
|
+
```javascript
|
18
|
+
const { SlashCommandBuilder } = require('vcord');
|
19
|
+
|
20
|
+
const command = new SlashCommandBuilder()
|
21
|
+
.setName('userinfo')
|
22
|
+
.setDescription('Get information about a user')
|
23
|
+
.addUserOption(option =>
|
24
|
+
option.setName('target')
|
25
|
+
.setDescription('The user to get info about')
|
26
|
+
.setRequired(false)
|
27
|
+
);
|
28
|
+
```
|
29
|
+
|
30
|
+
### Methods
|
31
|
+
- `setName(name)`: Set the command name (1-32 characters, lowercase)
|
32
|
+
- `setDescription(description)`: Set the command description (1-100 characters)
|
33
|
+
- `setDefaultPermission(boolean)`: Set if the command is enabled by default
|
34
|
+
- `addSubcommand(builder)`: Add a subcommand
|
35
|
+
- `addSubcommandGroup(builder)`: Add a subcommand group
|
36
|
+
- `addStringOption(builder)`: Add a string option
|
37
|
+
- `addIntegerOption(builder)`: Add an integer option
|
38
|
+
- `addBooleanOption(builder)`: Add a boolean option
|
39
|
+
- `addUserOption(builder)`: Add a user option
|
40
|
+
- `addChannelOption(builder)`: Add a channel option
|
41
|
+
- `addRoleOption(builder)`: Add a role option
|
42
|
+
- `addMentionableOption(builder)`: Add a mentionable option
|
43
|
+
- `addNumberOption(builder)`: Add a number option
|
44
|
+
- `addAttachmentOption(builder)`: Add an attachment option
|
45
|
+
|
46
|
+
## EmbedBuilder
|
47
|
+
|
48
|
+
The `EmbedBuilder` class helps you create rich message embeds.
|
49
|
+
|
50
|
+
```javascript
|
51
|
+
const { EmbedBuilder } = require('vcord');
|
52
|
+
|
53
|
+
const embed = new EmbedBuilder()
|
54
|
+
.setTitle('Hello World')
|
55
|
+
.setDescription('This is a description')
|
56
|
+
.setColor('#FF0000')
|
57
|
+
.addFields([
|
58
|
+
{ name: 'Field 1', value: 'Value 1' },
|
59
|
+
{ name: 'Field 2', value: 'Value 2' }
|
60
|
+
]);
|
61
|
+
```
|
62
|
+
|
63
|
+
### Methods
|
64
|
+
- `setTitle(title)`: Set the embed title
|
65
|
+
- `setDescription(description)`: Set the embed description
|
66
|
+
- `setColor(color)`: Set the embed color (hex code or integer)
|
67
|
+
- `setTimestamp(timestamp)`: Set the embed timestamp
|
68
|
+
- `setFooter(text, iconURL)`: Set the embed footer
|
69
|
+
- `setImage(url)`: Set the embed image
|
70
|
+
- `setThumbnail(url)`: Set the embed thumbnail
|
71
|
+
- `setAuthor(name, iconURL, url)`: Set the embed author
|
72
|
+
- `addFields(fields)`: Add multiple fields
|
73
|
+
- `addField(name, value, inline)`: Add a single field
|
74
|
+
|
75
|
+
## ComponentBuilder
|
76
|
+
|
77
|
+
The `ComponentBuilder` class and its subclasses help you create message components.
|
78
|
+
|
79
|
+
### ButtonBuilder
|
80
|
+
|
81
|
+
```javascript
|
82
|
+
const { ButtonBuilder } = require('vcord');
|
83
|
+
|
84
|
+
const button = new ButtonBuilder()
|
85
|
+
.setCustomId('click_me')
|
86
|
+
.setLabel('Click Me!')
|
87
|
+
.setStyle('PRIMARY');
|
88
|
+
```
|
89
|
+
|
90
|
+
### SelectMenuBuilder
|
91
|
+
|
92
|
+
```javascript
|
93
|
+
const { SelectMenuBuilder } = require('vcord');
|
94
|
+
|
95
|
+
const menu = new SelectMenuBuilder()
|
96
|
+
.setCustomId('select')
|
97
|
+
.setPlaceholder('Choose an option')
|
98
|
+
.addOptions([
|
99
|
+
{
|
100
|
+
label: 'Option 1',
|
101
|
+
value: 'option_1',
|
102
|
+
description: 'This is option 1'
|
103
|
+
}
|
104
|
+
]);
|
105
|
+
```
|
106
|
+
|
107
|
+
### TextInputBuilder
|
108
|
+
|
109
|
+
```javascript
|
110
|
+
const { TextInputBuilder } = require('vcord');
|
111
|
+
|
112
|
+
const input = new TextInputBuilder()
|
113
|
+
.setCustomId('name')
|
114
|
+
.setLabel('Your Name')
|
115
|
+
.setStyle('SHORT')
|
116
|
+
.setRequired(true);
|
117
|
+
```
|
118
|
+
|
119
|
+
## Best Practices
|
120
|
+
|
121
|
+
1. Always validate user input before creating commands
|
122
|
+
2. Use descriptive names and descriptions
|
123
|
+
3. Group related commands using subcommands
|
124
|
+
4. Keep embed content concise and well-formatted
|
125
|
+
5. Use appropriate component styles for better UX
|
126
|
+
|
127
|
+
## Error Handling
|
128
|
+
|
129
|
+
All builders include built-in validation and will throw descriptive errors if:
|
130
|
+
- Required fields are missing
|
131
|
+
- Values are invalid
|
132
|
+
- Limits are exceeded (e.g., too many fields in an embed)
|
133
|
+
|
134
|
+
## Examples
|
135
|
+
|
136
|
+
Check the [examples](../example) directory for complete working examples of using builders.
|