@stonyx/discord 0.1.1-beta.65 → 0.1.1-beta.66
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 +2 -2
- package/dist/bot.js +16 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,7 +178,7 @@ All methods are on the `DiscordBot` instance (accessible via `this._bot` in comm
|
|
|
178
178
|
|
|
179
179
|
### sendMessage(content, channelId, imagePath?)
|
|
180
180
|
|
|
181
|
-
Send a text message to a channel. Optionally attach an image file.
|
|
181
|
+
Send a text message to a channel with auto-chunking. Messages over 2000 characters are split at newline/space boundaries and sent sequentially. Optionally attach an image file (attached to the first chunk only).
|
|
182
182
|
|
|
183
183
|
Messages are delivered reliably across connection state transitions:
|
|
184
184
|
- If the bot is **ready**, the message is sent immediately.
|
|
@@ -299,7 +299,7 @@ Configuration is read from `stonyx/config` under `discord`:
|
|
|
299
299
|
| `eventHandlers` | `Array` — registered event handler instances |
|
|
300
300
|
| `client` | Discord.js `Client` instance (after init) |
|
|
301
301
|
| `ready` | `Promise` — resolves when the bot is connected and ready; re-pends on gateway disconnects |
|
|
302
|
-
| `sendMessage(content, channelId, imagePath?)` | Send a message to a channel (queues during disconnections, retries transient failures) |
|
|
302
|
+
| `sendMessage(content, channelId, imagePath?)` | Send a message to a channel with auto-chunking (queues during disconnections, retries transient failures) |
|
|
303
303
|
| `sendFile(file, messageObject)` | Replace a message with a file attachment |
|
|
304
304
|
| `reply(interaction, content)` | Reply with auto-chunking |
|
|
305
305
|
| `updateStatus(name, type?)` | Set bot presence |
|
package/dist/bot.js
CHANGED
|
@@ -159,11 +159,26 @@ export default class DiscordBot {
|
|
|
159
159
|
const channel = await this.client.channels.fetch(channelId);
|
|
160
160
|
if (!channel)
|
|
161
161
|
throw new Error('Invalid Channel ID');
|
|
162
|
+
const sendable = channel;
|
|
163
|
+
if (content.length > 2000) {
|
|
164
|
+
const chunks = chunkMessage('', content);
|
|
165
|
+
let firstMessage;
|
|
166
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
167
|
+
const options = { content: chunks[i] };
|
|
168
|
+
if (i === 0 && imagePath) {
|
|
169
|
+
options.files = [new AttachmentBuilder(imagePath)];
|
|
170
|
+
}
|
|
171
|
+
const msg = await sendable.send(options);
|
|
172
|
+
if (i === 0)
|
|
173
|
+
firstMessage = msg;
|
|
174
|
+
}
|
|
175
|
+
return firstMessage;
|
|
176
|
+
}
|
|
162
177
|
const options = { content };
|
|
163
178
|
if (imagePath) {
|
|
164
179
|
options.files = [new AttachmentBuilder(imagePath)];
|
|
165
180
|
}
|
|
166
|
-
return await
|
|
181
|
+
return await sendable.send(options);
|
|
167
182
|
}
|
|
168
183
|
async sendMessage(content, channelId, imagePath = null) {
|
|
169
184
|
if (this._connectionState === 'ready') {
|