discord-self-lite 0.1.0 → 0.1.2

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
@@ -59,11 +59,33 @@ const client = new Client();
59
59
  - `client.fetchChannel(channelId)` - Fetch channel from API
60
60
  - `client.fetchMessage(channelId, messageId)` - Fetch specific message
61
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
+
62
69
  #### Events
63
70
 
64
71
  - `ready` - Fired when client is ready
65
72
  - `messageCreate` - Fired when a message is created
66
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
+
67
89
  ### Message
68
90
 
69
91
  #### Methods
package/package.json CHANGED
@@ -1,64 +1,64 @@
1
- {
2
- "name": "discord-self-lite",
3
- "version": "0.1.0",
4
- "description": "Lightweight Discord selfbot library",
5
- "keywords": [
6
- "discord",
7
- "selfbot",
8
- "bot",
9
- "api",
10
- "websocket",
11
- "discord-api",
12
- "discord-bot",
13
- "discord-selfbot",
14
- "lightweight",
15
- "nodejs"
16
- ],
17
- "main": "src/index.js",
18
- "files": [
19
- "src",
20
- "README.md",
21
- "LICENSE"
22
- ],
23
- "exports": {
24
- ".": "./src/index.js",
25
- "./classes/Client": "./src/classes/Client.js",
26
- "./classes/WebhookClient": "./src/connection/webhook/WebhookClient.js"
27
- },
28
- "engines": {
29
- "node": ">=18.13.0"
30
- },
31
- "scripts": {
32
- "test": "eslint . && prettier --check .",
33
- "format": "prettier --write .",
34
- "fix": "eslint . --fix && prettier --write .",
35
- "docs": "echo \"📚 Documentation available at docs/README.md\"",
36
- "docs:html": "jsdoc -c jsdoc.conf.json"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/kyan0045/discord-self-lite.git"
41
- },
42
- "author": {
43
- "name": "Kyan Bosman",
44
- "email": "contact@kyanbosman.com",
45
- "url": "https://github.com/kyan0045"
46
- },
47
- "license": "GPL-3.0-or-later",
48
- "bugs": {
49
- "url": "https://github.com/kyan0045/discord-self-lite/issues"
50
- },
51
- "homepage": "https://github.com/kyan0045/discord-self-lite#readme",
52
- "funding": {
53
- "type": "github",
54
- "url": "https://github.com/sponsors/kyan0045"
55
- },
56
- "dependencies": {
57
- "ws": "^8.18.3"
58
- },
59
- "devDependencies": {
60
- "eslint-config-prettier": "^10.1.8",
61
- "eslint-plugin-prettier": "^5.5.4",
62
- "prettier": "^3.6.2"
63
- }
64
- }
1
+ {
2
+ "name": "discord-self-lite",
3
+ "version": "0.1.2",
4
+ "description": "Lightweight Discord selfbot library",
5
+ "keywords": [
6
+ "discord",
7
+ "selfbot",
8
+ "bot",
9
+ "api",
10
+ "websocket",
11
+ "discord-api",
12
+ "discord-bot",
13
+ "discord-selfbot",
14
+ "lightweight",
15
+ "nodejs"
16
+ ],
17
+ "main": "src/index.js",
18
+ "files": [
19
+ "src",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "exports": {
24
+ ".": "./src/index.js",
25
+ "./classes/Client": "./src/classes/Client.js",
26
+ "./classes/WebhookClient": "./src/connection/webhook/WebhookClient.js"
27
+ },
28
+ "engines": {
29
+ "node": ">=18.13.0"
30
+ },
31
+ "scripts": {
32
+ "test": "eslint . && prettier --check .",
33
+ "format": "prettier --write .",
34
+ "fix": "eslint . --fix && prettier --write .",
35
+ "docs": "echo \"📚 Documentation available at docs/README.md\"",
36
+ "docs:html": "jsdoc -c jsdoc.conf.json"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/kyan0045/discord-self-lite.git"
41
+ },
42
+ "author": {
43
+ "name": "Kyan Bosman",
44
+ "email": "contact@kyanbosman.com",
45
+ "url": "https://github.com/kyan0045"
46
+ },
47
+ "license": "GPL-3.0-or-later",
48
+ "bugs": {
49
+ "url": "https://github.com/kyan0045/discord-self-lite/issues"
50
+ },
51
+ "homepage": "https://github.com/kyan0045/discord-self-lite#readme",
52
+ "funding": {
53
+ "type": "github",
54
+ "url": "https://github.com/sponsors/kyan0045"
55
+ },
56
+ "dependencies": {
57
+ "ws": "^8.18.3"
58
+ },
59
+ "devDependencies": {
60
+ "eslint-config-prettier": "^10.1.8",
61
+ "eslint-plugin-prettier": "^5.5.4",
62
+ "prettier": "^3.6.2"
63
+ }
64
+ }
@@ -36,6 +36,7 @@ class Client extends EventEmitter {
36
36
  this.guilds = new Map(); // Cache for Guild instances
37
37
  this.channels = new Map(); // Cache for Channel instances
38
38
  this.sessionId = null; // Will be set from WebSocket READY event
39
+ this.user = null; // Will be set from WebSocket READY event
39
40
  }
40
41
 
41
42
  /**
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Represents a Discord user
3
+ */
4
+ class User {
5
+ /**
6
+ * Create a new User instance
7
+ * @param {Client} client - The Discord client
8
+ * @param {object} data - Raw user data from Discord API
9
+ */
10
+ constructor(client, data) {
11
+ this.client = client;
12
+ this.data = data;
13
+
14
+ // Copy all user properties
15
+ for (const [key, value] of Object.entries(data)) {
16
+ const camelKey = key.replace(/_([a-z])/g, (_, letter) =>
17
+ letter.toUpperCase(),
18
+ );
19
+ this[camelKey] = value;
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Set the user's presence/status
25
+ * @param {object} presence - Presence data
26
+ * @param {string} [presence.status] - Status: 'online', 'idle', 'dnd', 'invisible'
27
+ * @param {Array} [presence.activities] - Array of activity objects
28
+ * @param {boolean} [presence.afk] - Whether the user is AFK
29
+ * @param {number} [presence.since] - Unix timestamp of when the status was set
30
+ * @returns {void}
31
+ */
32
+ setPresence(presence) {
33
+ if (!this.client.ws || !this.client.ws.ready) {
34
+ throw new Error("Client is not connected");
35
+ }
36
+
37
+ const presenceData = {
38
+ status: presence.status || "online",
39
+ since: presence.since || 0,
40
+ activities: presence.activities || [],
41
+ afk: presence.afk || false,
42
+ };
43
+
44
+ // Send presence update via WebSocket
45
+ this.client.ws.send({
46
+ op: 3,
47
+ d: presenceData,
48
+ });
49
+
50
+ // Update client's stored presence
51
+ this.client.options.presence = presenceData;
52
+ }
53
+
54
+ /**
55
+ * Set the user's status (convenience method)
56
+ * @param {string} status - Status: 'online', 'idle', 'dnd', 'invisible'
57
+ * @returns {void}
58
+ */
59
+ setStatus(status) {
60
+ this.setPresence({
61
+ status: status,
62
+ since: this.client.options.presence.since,
63
+ activities: this.client.options.presence.activities,
64
+ afk: this.client.options.presence.afk,
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Set the user's activity
70
+ * @param {object} activity - Activity data
71
+ * @param {string} activity.name - Activity name
72
+ * @param {string} [activity.type=0] - Activity type (0=Playing, 1=Streaming, 2=Listening, 3=Watching, 5=Competing)
73
+ * @param {string} [activity.url] - Stream URL (for type 1)
74
+ * @returns {void}
75
+ */
76
+ setActivity(activity) {
77
+ const activities = activity ? [activity] : [];
78
+ this.setPresence({
79
+ status: this.client.options.presence.status,
80
+ since: this.client.options.presence.since,
81
+ activities: activities,
82
+ afk: this.client.options.presence.afk,
83
+ });
84
+ }
85
+ }
86
+
87
+ module.exports = User;
@@ -1,35 +1,36 @@
1
- async function clickButton(
2
- rest,
3
- channelId,
4
- messageId,
5
- applicationId,
6
- guildId,
7
- customId,
8
- sessionId,
9
- messageFlags = 0,
10
- ) {
11
- // Generate a snowflake-like nonce (simplified version)
12
- const nonce = Date.now().toString() + Math.random().toString(36).substring(2, 11);
13
-
14
- const payload = {
15
- type: 3, // MESSAGE_COMPONENT
16
- nonce,
17
- guild_id: guildId,
18
- channel_id: channelId,
19
- message_id: messageId,
20
- application_id: applicationId,
21
- session_id: sessionId,
22
- message_flags: messageFlags,
23
- data: {
24
- component_type: 2, // BUTTON
25
- custom_id: customId,
26
- },
27
- };
28
-
29
- return await rest.request("/interactions", {
30
- method: "POST",
31
- body: JSON.stringify(payload),
32
- });
33
- }
34
-
35
- module.exports = clickButton;
1
+ async function clickButton(
2
+ rest,
3
+ channelId,
4
+ messageId,
5
+ applicationId,
6
+ guildId,
7
+ customId,
8
+ sessionId,
9
+ messageFlags = 0,
10
+ ) {
11
+ // Generate a snowflake-like nonce (simplified version)
12
+ const nonce =
13
+ Date.now().toString() + Math.random().toString(36).substring(2, 11);
14
+
15
+ const payload = {
16
+ type: 3, // MESSAGE_COMPONENT
17
+ nonce,
18
+ guild_id: guildId,
19
+ channel_id: channelId,
20
+ message_id: messageId,
21
+ application_id: applicationId,
22
+ session_id: sessionId,
23
+ message_flags: messageFlags,
24
+ data: {
25
+ component_type: 2, // BUTTON
26
+ custom_id: customId,
27
+ },
28
+ };
29
+
30
+ return await rest.request("/interactions", {
31
+ method: "POST",
32
+ body: JSON.stringify(payload),
33
+ });
34
+ }
35
+
36
+ module.exports = clickButton;
@@ -3,6 +3,7 @@ const { EventEmitter } = require("events");
3
3
  const Message = require("../../classes/Message");
4
4
  const Guild = require("../../classes/Guild");
5
5
  const Channel = require("../../classes/Channel");
6
+ const User = require("../../classes/User");
6
7
  const WebSocketError = require("../../classes/WebSocketError");
7
8
 
8
9
  class DiscordWebSocket extends EventEmitter {
@@ -129,6 +130,7 @@ class DiscordWebSocket extends EventEmitter {
129
130
  case "READY":
130
131
  this.sessionId = message.d.session_id;
131
132
  this.client.sessionId = message.d.session_id;
133
+ this.client.user = new User(this.client, message.d.user);
132
134
  this.ready = true;
133
135
  this.client.emit("ready", message.d);
134
136
  break;
package/src/index.js CHANGED
@@ -1,41 +1,41 @@
1
- /**
2
- * discord-self-lite - A lightweight Discord selfbot library
3
- * @module discord-self-lite
4
- * @version 0.1.0
5
- * @description A modern, lightweight Discord selfbot library with webhook support, built for Node.js 22+ with zero external dependencies (except ws for WebSocket connections).
6
- *
7
- * @example
8
- * // Import the library
9
- * const { Client, WebhookClient } = require('discord-self-lite');
10
- *
11
- * // Create a Discord client
12
- * const client = new Client();
13
- * client.login('your-token');
14
- *
15
- * // Create a webhook client
16
- * const webhook = new WebhookClient('webhook-url');
17
- * await webhook.send('Hello, world!');
18
- */
19
-
20
- const Client = require("./classes/Client");
21
- const WebhookClient = require("./connection/webhook/WebhookClient");
22
-
23
- /**
24
- * Main package exports
25
- * @namespace discord-self-lite
26
- */
27
- module.exports = {
28
- /**
29
- * The main Discord client class for connecting to Discord and handling events
30
- * @type {Client}
31
- * @see {@link Client}
32
- */
33
- Client,
34
-
35
- /**
36
- * Discord webhook client class for sending messages via webhooks
37
- * @type {WebhookClient}
38
- * @see {@link WebhookClient}
39
- */
40
- WebhookClient,
41
- };
1
+ /**
2
+ * discord-self-lite - A lightweight Discord selfbot library
3
+ * @module discord-self-lite
4
+ * @version 0.1.0
5
+ * @description A modern, lightweight Discord selfbot library with webhook support, built for Node.js 22+ with zero external dependencies (except ws for WebSocket connections).
6
+ *
7
+ * @example
8
+ * // Import the library
9
+ * const { Client, WebhookClient } = require('discord-self-lite');
10
+ *
11
+ * // Create a Discord client
12
+ * const client = new Client();
13
+ * client.login('your-token');
14
+ *
15
+ * // Create a webhook client
16
+ * const webhook = new WebhookClient('webhook-url');
17
+ * await webhook.send('Hello, world!');
18
+ */
19
+
20
+ const Client = require("./classes/Client");
21
+ const WebhookClient = require("./connection/webhook/WebhookClient");
22
+
23
+ /**
24
+ * Main package exports
25
+ * @namespace discord-self-lite
26
+ */
27
+ module.exports = {
28
+ /**
29
+ * The main Discord client class for connecting to Discord and handling events
30
+ * @type {Client}
31
+ * @see {@link Client}
32
+ */
33
+ Client,
34
+
35
+ /**
36
+ * Discord webhook client class for sending messages via webhooks
37
+ * @type {WebhookClient}
38
+ * @see {@link WebhookClient}
39
+ */
40
+ WebhookClient,
41
+ };