{"record":{"id":"09a775a083741363","repo":"jackwener/OpenCLI","slug":"pass-url-or-guild-channel-to-choose-a-discor","errorCode":null,"errorMessage":"Pass --url or --guild/--channel to choose a Discord channel.","messagePattern":"Pass --url or --guild/--channel to choose a Discord channel\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/discord-app/utils.js","lineNumber":473,"sourceCode":"    if (!guild) return true;\n    return String(row.guild_id || '') === guild || normalizeDiscordName(row.Server) === normalizeDiscordName(guild);\n}\n\nexport async function resolveDiscordChannelTarget(page, kwargs = {}, options = {}) {\n    const urlArg = stringArg(kwargs.url);\n    if (urlArg) {\n        const parsed = parseDiscordChannelUrl(urlArg);\n        if (!parsed || parsed.thread_id) {\n            throw new ArgumentError('--url must be a Discord channel URL like https://discord.com/channels/<guild_id>/<channel_id>.');\n        }\n        return parsed;\n    }\n\n    const guildArg = stringArg(kwargs.guild);\n    const channelArg = stringArg(kwargs.channel);\n    if (!guildArg && !channelArg) {\n        if (options.required) {\n            throw new ArgumentError('Pass --url or --guild/--channel to choose a Discord channel.');\n        }\n        return null;\n    }\n    if (!channelArg) {\n        throw new ArgumentError('Pass --channel with --guild, or use --url.');\n    }\n\n    let guildId = guildArg;\n    if (guildArg && !isDiscordSnowflake(guildArg) && guildArg !== '@me') {\n        const server = (await listDiscordServers(page)).find((row) => rowMatchesGuild(row, guildArg));\n        if (server?.guild_id) guildId = String(server.guild_id);\n    }\n\n    if (guildId && isDiscordSnowflake(guildId) && isDiscordSnowflake(channelArg)) {\n        return {\n            guild_id: guildId,\n            channel_id: channelArg,\n            url: buildDiscordChannelUrl({ guildId, channelId: channelArg }),","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/discord-app/utils.js#L455-L491","documentation":"resolveDiscordChannelTarget throws this ArgumentError when no channel selector is supplied at all (no --url, no --guild, no --channel) while options.required is set. The caller explicitly demanded a channel target, so returning null is not allowed.","triggerScenarios":"Invoking a command that calls resolveDiscordChannelTarget with { required: true } and providing none of --url, --guild, or --channel in kwargs.","commonSituations":"Forgetting required flags in scripts/CI; omitting arguments after refactoring a command; assuming a previously selected channel persists between invocations when it does not.","solutions":["Pass --url https://discord.com/channels/<guild_id>/<channel_id>.","Or pass both --guild and --channel.","Or pass --channel together with --guild as numeric snowflake ids (run \"opencli discord-app channels -f json\" to find them)."],"exampleFix":"// before\nopencli discord-app messages\n// after\nopencli discord-app messages --url https://discord.com/channels/123456789/987654321","handlingStrategy":"validation","validationCode":"if (!opts.url && !opts.guild && !opts.channel) throw new Error('Provide --url or --guild/--channel before invoking');","typeGuard":"function hasChannelSelector(k = {}) { return Boolean(k.url || k.guild || k.channel); }","tryCatchPattern":"try { await runCommand(args); } catch (e) { if (String(e.message).startsWith('Pass --url or --guild/--channel')) { console.error('Usage: --url <channel-url> | --guild <g> --channel <c>'); } else throw e; }","preventionTips":["Wrap Discord CLI calls in scripts that assert required flags exist first.","Prefer --url so a single argument carries both ids.","Keep a documented command template with all flags filled in."],"tags":["discord","cli","missing-argument","argument-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}