discord-self-lite 0.1.9 → 0.1.10

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 CHANGED
@@ -45,126 +45,17 @@ client.on("messageCreate", async (message) => {
45
45
 
46
46
  ## API Reference
47
47
 
48
- ### Client
48
+ The full API documentation is available in the [`docs/api/`](docs/api/README.md) directory. Here are the core classes:
49
49
 
50
- ```javascript
51
- const { Client } = require("discord-self-lite");
52
- const client = new Client();
53
- ```
54
-
55
- #### Methods
56
-
57
- - `client.login(token)` - Login with user token
58
- - `client.getChannel(channelId)` - Get cached channel
59
- - `client.fetchChannel(channelId)` - Fetch channel from API
60
- - `client.fetchMessage(channelId, messageId)` - Fetch specific message
61
-
62
- #### Properties
63
-
64
- - `client.user` - Current user object (available after ready event)
65
- - `client.guilds` - Map of cached guild instances
66
- - `client.channels` - Map of cached channel instances
67
- - `client.sessionId` - Session ID from Discord
68
-
69
- #### Events
70
-
71
- - `ready` - Fired when client is ready
72
- - `messageCreate` - Fired when a message is created
73
-
74
- ### User
75
-
76
- #### Methods
77
-
78
- - `user.setStatus(status)` - Set user status ('online', 'idle', 'dnd', 'invisible')
79
- - `user.setPresence(presence)` - Set full presence data
80
- - `user.setActivity(activity)` - Set user activity
81
-
82
- #### Properties
83
-
84
- - `user.id` - User ID
85
- - `user.username` - Username
86
- - `user.discriminator` - Discriminator (4-digit number)
87
- - `user.avatar` - Avatar hash
88
-
89
- ### Message
90
-
91
- #### Methods
92
-
93
- - `message.reply(content, options)` - Reply to the message
94
- - `message.react(emoji)` - React to the message
95
- - `message.clickButton(identifier)` - Click a button on the message
96
- - `identifier` can be:
97
- - `null` or omitted: clicks first button
98
- - `number`: clicks button at index (0-based)
99
- - `string`: clicks button with custom ID
100
-
101
- #### Properties
102
-
103
- - `message.content` - Message content
104
- - `message.author` - Message author
105
- - `message.channel` - Message channel
106
- - `message.guild` - Message guild (null for DMs)
107
- - `message.components` - Message components (buttons, etc.)
108
-
109
- ### Channel
110
-
111
- #### Methods
112
-
113
- - `channel.send(content, options)` - Send a message to the channel
114
- - `channel.fetchMessages(options)` - Fetch messages from the channel
115
-
116
- #### Properties
117
-
118
- - `channel.id` - Channel ID
119
- - `channel.name` - Channel name
120
- - `channel.type` - Channel type
121
-
122
- ### Guild
123
-
124
- #### Methods
125
-
126
- - `guild.getChannels()` - Get cached channels for this guild
127
- - `guild.fetchChannels()` - Fetch all channels for this guild from API
128
- - `guild.getChannel(channelId)` - Get a specific channel from cache
129
- - `guild.fetchChannel(channelId)` - Fetch a specific channel from API
130
-
131
- #### Properties
132
-
133
- - `guild.id` - Guild ID
134
- - `guild.name` - Guild name
135
- - `guild.icon` - Guild icon hash
136
- - `guild.ownerId` - Guild owner ID
137
-
138
- ### WebhookClient
139
-
140
- Send messages to Discord webhooks with support for embeds and more.
141
-
142
- ```javascript
143
- const { WebhookClient } = require("discord-self-lite");
144
- const webhook = new WebhookClient("YOUR_WEBHOOK_URL", {
145
- username: "My Bot",
146
- avatarURL: "https://example.com/avatar.png",
147
- });
148
- ```
149
-
150
- #### Constructor
151
-
152
- - `new WebhookClient(url, options)` - Create a webhook client
153
- - `url` - Discord webhook URL
154
- - `options.username` - Default username for messages
155
- - `options.avatarURL` - Default avatar URL for messages
156
-
157
- #### Methods
158
-
159
- - `webhook.send(content, options)` - Send a message (supports text, embeds, and objects)
160
- - `webhook.edit(messageId, content, options)` - Edit a message
161
- - `webhook.delete(messageId)` - Delete a message
162
- - `webhook.fetchMessage(messageId)` - Fetch a message
163
-
164
- #### Static Methods
50
+ - **[`Client`](docs/api/Client.md)** - Main entry point, connection manager, and cache storage.
51
+ - **[`User`](docs/api/User.md) & [`ClientUser`](docs/api/ClientUser.md)** - Represents Discord users and the logged-in selfbot.
52
+ - **[`Message`](docs/api/Message.md)** - Represents text messages, supports replying, reacting, and clicking buttons.
53
+ - **[`Channel`](docs/api/Channel.md)** - Represents Text, DM, or Voice channels to fetch or send messages.
54
+ - **[`Guild`](docs/api/Guild.md) & [`GuildMember`](docs/api/GuildMember.md)** - Represents Discord servers and their members.
55
+ - **[`WebhookClient`](docs/api/WebhookClient.md)** - Standalone client to send requests via webhooks.
56
+ - **[`Permissions`](docs/api/Permissions.md) & [`BitField`](docs/api/BitField.md)** - Utility classes for resolving and checking Discord permissions.
165
57
 
166
- - `WebhookClient.createEmbed(data)` - Create an embed object
167
- - `WebhookClient.parseURL(url)` - Parse webhook URL to get ID and token
58
+ _Check the [Complete API Reference](docs/api/README.md) for full properties, methods, and examples of each._
168
59
 
169
60
  ## Examples
170
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-self-lite",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Lightweight Discord selfbot library",
5
5
  "keywords": [
6
6
  "discord",
@@ -32,8 +32,7 @@
32
32
  "test": "eslint . && prettier --check .",
33
33
  "format": "prettier --write .",
34
34
  "fix": "eslint . --fix && prettier --write .",
35
- "docs": "echo \"📚 Documentation available at docs/README.md\"",
36
- "docs:html": "jsdoc -c jsdoc.conf.json"
35
+ "docs": "echo \"📚 Documentation available at docs/README.md\""
37
36
  },
38
37
  "repository": {
39
38
  "type": "git",
@@ -99,39 +99,63 @@ class Client extends EventEmitter {
99
99
  }
100
100
 
101
101
  /**
102
- * Get channel from cache, or create empty instance if not cached
102
+ * Get channel from cache
103
103
  * @param {string} id - The channel ID
104
- * @returns {Channel} The channel instance
104
+ * @returns {Channel|null} The cached channel instance or null
105
105
  */
106
106
  getChannel(id) {
107
- if (!this.channels.has(id)) {
108
- this.channels.set(id, new Channel(this, this.rest, id));
109
- }
110
- return this.channels.get(id);
107
+ return this.channels.get(id) || null;
111
108
  }
112
109
 
113
110
  /**
114
- * Get guild from cache, or create empty instance if not cached
111
+ * Resolve channel from cache or fetch from API
112
+ * @param {string} id - The channel ID
113
+ * @returns {Promise<Channel>} The resolved channel instance
114
+ */
115
+ async resolveChannel(id) {
116
+ const cached = this.getChannel(id);
117
+ if (cached) return cached;
118
+ return await this.fetchChannel(id);
119
+ }
120
+
121
+ /**
122
+ * Get guild from cache
115
123
  * @param {string} id - The guild ID
116
- * @returns {Guild} The guild instance
124
+ * @returns {Guild|null} The cached guild instance or null
117
125
  */
118
126
  getGuild(id) {
119
- if (!this.guilds.has(id)) {
120
- this.guilds.set(id, new Guild(this, this.rest, id));
121
- }
122
- return this.guilds.get(id);
127
+ return this.guilds.get(id) || null;
128
+ }
129
+
130
+ /**
131
+ * Resolve guild from cache or fetch from API
132
+ * @param {string} id - The guild ID
133
+ * @returns {Promise<Guild>} The resolved guild instance
134
+ */
135
+ async resolveGuild(id) {
136
+ const cached = this.getGuild(id);
137
+ if (cached) return cached;
138
+ return await this.fetchGuild(id);
123
139
  }
124
140
 
125
141
  /**
126
- * Get user from cache, or create lightweight instance if not cached
142
+ * Get user from cache
127
143
  * @param {string} id - The user ID
128
- * @returns {User} The User instance
144
+ * @returns {User|null} The cached user instance or null
129
145
  */
130
146
  getUser(id) {
131
- if (!this.users.has(id)) {
132
- this.users.set(id, new User(this, { id }));
133
- }
134
- return this.users.get(id);
147
+ return this.users.get(id) || null;
148
+ }
149
+
150
+ /**
151
+ * Resolve user from cache or fetch from API
152
+ * @param {string} id - The user ID
153
+ * @returns {Promise<User>} The resolved user instance
154
+ */
155
+ async resolveUser(id) {
156
+ const cached = this.getUser(id);
157
+ if (cached) return cached;
158
+ return await this.fetchUser(id);
135
159
  }
136
160
 
137
161
  /**
@@ -44,7 +44,7 @@ class Guild {
44
44
  /**
45
45
  * Get a channel from this guild (from cache)
46
46
  * @param {string} channelId - The channel ID
47
- * @returns {Channel} The channel instance
47
+ * @returns {Channel|null} The cached channel instance or null
48
48
  */
49
49
  getChannel(channelId) {
50
50
  const channel = this.client.getChannel(channelId);
@@ -42,7 +42,7 @@ class Message {
42
42
 
43
43
  /**
44
44
  * Get the channel this message was sent in
45
- * @returns {Channel} The channel instance
45
+ * @returns {Channel|null} The cached channel instance, or null if not cached
46
46
  */
47
47
  get channel() {
48
48
  return this.client.getChannel(this.channelId);
@@ -89,11 +89,12 @@ class Message {
89
89
  * @returns {Promise<object>} The sent reply message data
90
90
  */
91
91
  async reply(payload) {
92
+ const channel = await this.client.resolveChannel(this.channelId);
92
93
  const replyPayload =
93
94
  typeof payload === "string"
94
95
  ? { content: payload, message_reference: { message_id: this.id } }
95
96
  : { ...payload, message_reference: { message_id: this.id } };
96
- return await this.channel.send(replyPayload);
97
+ return await channel.send(replyPayload);
97
98
  }
98
99
 
99
100
  /**
@@ -203,14 +204,11 @@ class Message {
203
204
  const channelId = ref.channelId || ref.channel_id || this.channelId;
204
205
  if (!messageId || !channelId) return null;
205
206
 
206
- // Try to get channel from cache or fetch from API
207
- let channel = this.client.getChannel(channelId);
208
- if (!channel) {
209
- try {
210
- channel = await this.client.fetchChannel(channelId);
211
- } catch {
212
- return null;
213
- }
207
+ let channel;
208
+ try {
209
+ channel = await this.client.resolveChannel(channelId);
210
+ } catch {
211
+ return null;
214
212
  }
215
213
 
216
214
  try {