@hoverlover/cc-discord 0.5.5 → 0.5.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoverlover/cc-discord",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Discord <-> Claude Code relay: use your Claude subscription to power per-channel AI bots",
5
5
  "type": "module",
6
6
  "bin": {
@@ -54,6 +54,18 @@ async function ensureTraceThread(client: Client, channelId: string): Promise<Thr
54
54
  const failedAt = failedChannels.get(channelId);
55
55
  if (failedAt && Date.now() - failedAt < FAILURE_COOLDOWN_MS) return null;
56
56
 
57
+ // Quick-fetch to detect threads: can't create trace threads inside threads
58
+ try {
59
+ const ch = await client.channels.fetch(channelId);
60
+ if (ch?.isThread()) {
61
+ failedChannels.set(channelId, Date.now());
62
+ return null;
63
+ }
64
+ } catch {
65
+ // Channel doesn't exist or inaccessible — fall through to cached/DB path
66
+ // which will also fail and trigger cooldown
67
+ }
68
+
57
69
  // Check in-memory cache first
58
70
  const cachedThreadId = threadCache.get(channelId);
59
71
  if (cachedThreadId) {
@@ -156,7 +168,13 @@ async function ensureTraceThread(client: Client, channelId: string): Promise<Thr
156
168
  threadCache.set(channelId, thread.id);
157
169
  return thread;
158
170
  } catch (err) {
159
- console.error(`[Trace] Failed to create trace thread for channel ${channelId}:`, err);
171
+ const code = (err as any)?.code;
172
+ if (code === 10003 || code === 50001 || code === 50013) {
173
+ console.warn(`[Trace] Cannot create trace thread for channel ${channelId} (${code}) — backing off 5m`);
174
+ failedChannels.set(channelId, Date.now());
175
+ } else {
176
+ console.error(`[Trace] Failed to create trace thread for channel ${channelId}:`, err);
177
+ }
160
178
  return null;
161
179
  }
162
180
  }
@@ -313,9 +331,9 @@ async function flushTraceEvents(client: Client) {
313
331
  postedIds.push(...channelEvents.map((e) => e.id));
314
332
  } catch (err) {
315
333
  const code = (err as any)?.code;
316
- if (code === 50001 || code === 50013) {
317
- // Missing Access or Missing Permissions — clear cache and back off
318
- console.warn(`[Trace] No access to trace thread for channel ${channelId} (${code}) — backing off 5m`);
334
+ if (code === 50001 || code === 50013 || code === 10003) {
335
+ // Missing Access, Missing Permissions, or Unknown Channel — clear cache and back off
336
+ console.warn(`[Trace] Cannot access trace thread for channel ${channelId} (${code}) — backing off 5m`);
319
337
  threadCache.delete(channelId);
320
338
  failedChannels.set(channelId, Date.now());
321
339
  // Mark as posted to avoid infinite retry on permanent access errors