jackwener/OpenCLI · error · ArgumentError

Could not resolve Discord thread "${threadArg}". Open the pa

Error message

Could not resolve Discord thread "${threadArg}". Open the parent forum/channel first, or pass --guild and --channel ids with --thread.

What it means

resolveDiscordThreadTarget throws this ArgumentError when it cannot turn the provided --thread value into a resolvable thread: no current channel context, no parsable thread URL, and no --guild/--channel pair supplied. The library needs either ambient channel context or explicit parent ids to look up the thread.

Source

Thrown at clis/discord-app/utils.js:667

            }),
        };
    }

    const current = await getCurrentDiscordRoute(page);
    if (current?.guild_id && current?.channel_id) {
        return {
            guild_id: current.guild_id,
            channel_id: current.channel_id,
            thread_id: threadArg,
            url: buildDiscordChannelUrl({
                guildId: current.guild_id,
                channelId: current.channel_id,
                threadId: threadArg,
            }),
        };
    }

    throw new ArgumentError(
        `Could not resolve Discord thread "${threadArg}".`,
        'Open the parent forum/channel first, or pass --guild and --channel ids with --thread.',
    );
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Add --guild <guild_id> --channel <parent_channel_id> alongside --thread
  2. Open/resolve the parent forum or channel first so current.channel_id is available
  3. Pass the full thread URL via --url so it can be parsed directly
  4. Verify the thread id is the numeric snowflake id, not the thread name

Example fix

// before
cli thread-read --thread my-thread
// after
cli thread-read --guild 123456789 --channel 987654321 --thread 112233445566778899
Defensive patterns

Strategy: validation

Validate before calling

if (args.thread && !args.guild && !args.channel && !/^https:\/\/(discord|canary\.discord)\.com\/channels\//.test(args.thread)) throw new Error('Pass --guild and --channel ids with --thread, or a thread --url');

Type guard

function hasThreadContext(a) { return Boolean(a?.url) || Boolean(a?.thread && a.guild && a.channel); }

Try / catch

try { await target(args); } catch (e) { if (e instanceof ArgumentError && e.message.includes('Could not resolve Discord thread')) { console.error('Supply parent context: --guild <id> --channel <id> --thread <id>'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Passing --thread <id> without --guild/--channel while no parent forum/channel is currently selected; passing a URL that parseDiscordChannelUrl does not recognize as a thread URL; passing a thread name instead of an id.

Common situations: Running the CLI in a fresh session with no current channel; thread id copied from a webhook or bot context without the parent forum id; renamed/deleted thread whose URL no longer parses as a thread URL.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/a8883e2fce03a8b2. Report an issue: GitHub.