dcsv.js 1.0.0 → 1.0.1

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
@@ -93,6 +93,67 @@ dcsv.js emits standard Discord event names as per [Discord API Docs](https://dis
93
93
  - `VOICE_STATE_UPDATE`
94
94
  - ...and all others!
95
95
 
96
+ ## 🍳 Cookbook / Recipes
97
+
98
+ Since **dcsv.js** is stackless, you rely on the **Discord API** for data. Here are common patterns:
99
+
100
+ ### 1. Fetching User Banner
101
+ We don't cache users. To get a banner, fetch the user profile dynamically.
102
+
103
+ ```javascript
104
+ // GET /users/{id}
105
+ const user = await client.request('GET', `/users/${userId}`);
106
+
107
+ if (user.banner) {
108
+ const ext = user.banner.startsWith('a_') ? 'gif' : 'png';
109
+ const url = `https://cdn.discordapp.com/banners/${user.id}/${user.banner}.${ext}?size=1024`;
110
+ console.log(url);
111
+ }
112
+ ```
113
+
114
+ ### 2. Fetching Server Details
115
+ Need member counts? Ask the API.
116
+
117
+ ```javascript
118
+ // GET /guilds/{id}?with_counts=true
119
+ const guild = await client.request('GET', `/guilds/${guildId}?with_counts=true`);
120
+
121
+ console.log(`Server: ${guild.name}`);
122
+ console.log(`Members: ${guild.approximate_member_count}`);
123
+ console.log(`Online: ${guild.approximate_presence_count}`);
124
+ ```
125
+
126
+ ### 3. Sending an Embed
127
+ We support standard Discord Embed objects.
128
+
129
+ ```javascript
130
+ await client.createMessage(channelId, {
131
+ content: "Here is your info:",
132
+ embeds: [{
133
+ title: "Hello World",
134
+ color: 0x00FF00, // Hex Color
135
+ description: "This is a stackless embed.",
136
+ fields: [
137
+ { name: "Field 1", value: "Value 1", inline: true }
138
+ ]
139
+ }]
140
+ });
141
+ ```
142
+
143
+ ### 4. Handling Buttons (Interactions)
144
+ ```javascript
145
+ client.on('interactionCreate', async (interaction) => {
146
+ if (interaction.isButton()) {
147
+ if (interaction.customId === 'click_me') {
148
+ await interaction.reply({
149
+ content: "You clicked the button!",
150
+ flags: 64 // Ephemeral (Hidden)
151
+ });
152
+ }
153
+ }
154
+ });
155
+ ```
156
+
96
157
  ## 🤝 Contributing
97
158
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
98
159
 
@@ -0,0 +1,82 @@
1
+ const { Client, GatewayIntentBits } = require('../index');
2
+
3
+ // 1. Setup Client
4
+ const client = new Client({
5
+ intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent | GatewayIntentBits.GuildMembers,
6
+ shards: 'auto',
7
+ debug: true
8
+ });
9
+
10
+ client.on('ready', () => {
11
+ console.log(`logged in as ${client.user.username}`);
12
+ });
13
+
14
+ client.on('messageCreate', async (msg) => {
15
+ if (msg.author.bot) return;
16
+
17
+ // EXAMPLE 1: Fetching User Banner (Stackless)
18
+ // Since we don't cache users, we fetch fresh data from API
19
+ if (msg.content === '!banner') {
20
+ try {
21
+ // Raw API Call: GET /users/{id}
22
+ const user = await client.request('GET', `/users/${msg.author.id}`);
23
+
24
+ if (user.banner) {
25
+ // Construct CDN URL
26
+ const extension = user.banner.startsWith('a_') ? 'gif' : 'png';
27
+ const url = `https://cdn.discordapp.com/banners/${user.id}/${user.banner}.${extension}?size=512`;
28
+
29
+ await client.createMessage(msg.channel_id, {
30
+ content: `Here is your banner: ${url}`
31
+ });
32
+ } else {
33
+ await client.createMessage(msg.channel_id, { content: 'You have no banner set.' });
34
+ }
35
+ } catch (err) {
36
+ console.error(err);
37
+ }
38
+ }
39
+
40
+ // EXAMPLE 2: Fetching Server Details (Stackless)
41
+ if (msg.content === '!serverinfo') {
42
+ try {
43
+ // We can use the helper client.getGuild() or raw request
44
+ // with_counts=true key to get exact member counts
45
+ const guild = await client.request('GET', `/guilds/${msg.guild_id}?with_counts=true`);
46
+
47
+ const embed = {
48
+ title: guild.name,
49
+ description: guild.description || 'No description',
50
+ fields: [
51
+ { name: 'Owner ID', value: guild.owner_id, inline: true },
52
+ { name: 'Members', value: String(guild.approximate_member_count), inline: true },
53
+ { name: 'Boosts', value: String(guild.premium_subscription_count), inline: true }
54
+ ],
55
+ thumbnail: {
56
+ url: guild.icon ? `https://cdn.discordapp.com/icons/${guild.id}/${guild.icon}.png` : null
57
+ }
58
+ };
59
+
60
+ await client.createMessage(msg.channel_id, { embeds: [embed] });
61
+ } catch (err) {
62
+ console.error(err);
63
+ }
64
+ }
65
+ });
66
+
67
+ // EXAMPLE 3: Handling Raw Events (e.g., specific reaction add)
68
+ client.on('MESSAGE_REACTION_ADD', async (event) => {
69
+ // event contains { user_id, channel_id, message_id, emoji ... }
70
+ console.log(`User ${event.user_id} reacted with ${event.emoji.name}`);
71
+
72
+ // We can interact immediately without fetching the message object!
73
+ if (event.emoji.name === '⭐') {
74
+ await client.createMessage(event.channel_id, {
75
+ content: `<@${event.user_id}> you starred a message!`
76
+ });
77
+ }
78
+ });
79
+
80
+
81
+ //client.login('TOKEN');
82
+ console.log("Edit this file and add your token to test!");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dcsv.js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Ultra High Performance, Stackless Discord Interaction Library. Optimized for low memory usage and high scale.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -27,4 +27,4 @@
27
27
  "type": "git",
28
28
  "url": "https://github.com/dcsv-project/dcsv.js"
29
29
  }
30
- }
30
+ }