@stonyx/discord 0.1.1-beta.55 → 0.1.1-beta.56

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
@@ -241,10 +241,10 @@ const guild = await bot.getGuild();
241
241
 
242
242
  ### clearChannelMessages(channelId)
243
243
 
244
- Delete all fetched messages in a channel (up to `maxMessagesPerRequest`).
244
+ Delete all fetched messages in a channel (up to `maxMessagesPerRequest`). Awaits every delete via `Promise.allSettled` and resolves with a structured `{ deleted, failed, errors }` so callers can act on partial failure. Never throws on individual delete failures; emits a single `log.warn` summary when any deletes fail.
245
245
 
246
246
  ```javascript
247
- await bot.clearChannelMessages('123456789');
247
+ const { deleted, failed, errors } = await bot.clearChannelMessages('123456789');
248
248
  ```
249
249
 
250
250
  ### giveRole(memberId, roleId)
@@ -297,7 +297,7 @@ Configuration is read from `stonyx/config` under `discord`:
297
297
  | `getChannelMessages(channelId, options?)` | Fetch channel messages |
298
298
  | `getChannelMessage(channelId, messageId)` | Fetch a single message |
299
299
  | `getGuild(guildId?)` | Fetch a guild |
300
- | `clearChannelMessages(channelId)` | Delete messages in a channel |
300
+ | `clearChannelMessages(channelId)` | Delete messages in a channel; returns `{ deleted, failed, errors }` and never throws on partial failure |
301
301
  | `giveRole(memberId, roleId)` | Add a role to a member |
302
302
  | `close()` | Destroy the Discord client and clear singleton |
303
303
  | `reset()` | Close + clear all commands and handlers |
package/dist/bot.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { Client } from 'discord.js';
2
2
  import type { ChatInputCommandInteraction, Message } from 'discord.js';
3
+ export interface ClearChannelMessagesResult {
4
+ deleted: number;
5
+ failed: number;
6
+ errors: Error[];
7
+ }
3
8
  interface CommandInstance {
4
9
  data?: {
5
10
  name: string;
@@ -36,7 +41,7 @@ export default class DiscordBot {
36
41
  getChannelMessages(channelId: string, options?: Record<string, unknown>): Promise<unknown>;
37
42
  getChannelMessage(channelId: string, messageId: string): Promise<unknown>;
38
43
  getGuild(guildId?: string): Promise<unknown>;
39
- clearChannelMessages(channelId: string): Promise<unknown[]>;
44
+ clearChannelMessages(channelId: string): Promise<ClearChannelMessagesResult>;
40
45
  giveRole(memberId: string, roleId: string): Promise<void>;
41
46
  close(): void;
42
47
  reset(): void;
package/dist/bot.js CHANGED
@@ -186,10 +186,20 @@ export default class DiscordBot {
186
186
  return await this.client.guilds.fetch(guildId || config.discord.serverId || '');
187
187
  }
188
188
  async clearChannelMessages(channelId) {
189
- const promises = [];
190
189
  const messages = await this.getChannelMessages(channelId);
191
- messages.forEach(message => promises.push(message.delete()));
192
- return Promise.all(promises);
190
+ const settled = await Promise.allSettled([...messages.values()].map(m => m.delete()));
191
+ const errors = settled
192
+ .filter((s) => s.status === 'rejected')
193
+ .map(s => s.reason instanceof Error ? s.reason : new Error(String(s.reason)));
194
+ const result = {
195
+ deleted: settled.length - errors.length,
196
+ failed: errors.length,
197
+ errors,
198
+ };
199
+ if (result.failed > 0) {
200
+ log.warn(`clearChannelMessages partial failure on channel ${channelId}: deleted=${result.deleted} failed=${result.failed} errors=${errors.map(String).join('; ')}`);
201
+ }
202
+ return result;
193
203
  }
194
204
  async giveRole(memberId, roleId) {
195
205
  const guild = await this.getGuild();
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.1.1-beta.55",
7
+ "version": "0.1.1-beta.56",
8
8
  "description": "Discord bot module for the Stonyx framework",
9
9
  "main": "dist/main.js",
10
10
  "types": "dist/main.d.ts",