Tyrrrz/DiscordChatExporter · error · CommandException

Option --media-dir cannot be used without --media.

Error message

Option --media-dir cannot be used without --media.

What it means

Thrown by ExportCommandBase.ExportAsync as a CommandException when the user specifies a custom assets directory (--media-dir) without enabling asset download (--media). The assets directory is only used when assets are downloaded, so specifying it alone is rejected up-front. It is a non-fatal CLI usage error.

Source

Thrown at DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs:165

    [field: AllowNull, MaybeNull]
    protected ChannelExporter Exporter => field ??= new ChannelExporter(Discord);

    protected async ValueTask ExportAsync(IConsole console, IReadOnlyList<Channel> channels)
    {
        var cancellationToken = console.RegisterCancellationHandler();

        // Asset reuse can only be enabled if the download assets option is set
        // https://github.com/Tyrrrz/DiscordChatExporter/issues/425
        if (ShouldReuseAssets && !ShouldDownloadAssets)
        {
            throw new CommandException("Option --reuse-media cannot be used without --media.");
        }

        // Assets directory can only be specified if the download assets option is set
        if (!string.IsNullOrWhiteSpace(AssetsDirPath) && !ShouldDownloadAssets)
        {
            throw new CommandException("Option --media-dir cannot be used without --media.");
        }

        // Make sure the user does not try to export multiple channels into one file.
        // Output path must either be a directory or contain template tokens for this to work.
        // Validate this up-front, before fetching threads, because thread fetching can take a
        // long time and it's frustrating to fail only after it completes.
        // https://github.com/Tyrrrz/DiscordChatExporter/issues/799
        // https://github.com/Tyrrrz/DiscordChatExporter/issues/917
        // https://github.com/Tyrrrz/DiscordChatExporter/issues/1549
        var mayExportMultipleChannels =
            // Multiple channels were provided explicitly
            channels.Count > 1
            // Thread inclusion can add more channels to the export
            || ThreadInclusionMode != ThreadInclusionMode.None;

        var isValidOutputPath =
            // Anything is valid when exporting a single channel
            !mayExportMultipleChannels

View on GitHub (pinned to f6865c8216)

Solutions

  1. Add the --media flag alongside --media-dir (e.g. `--media --media-dir ./assets`).
  2. Drop --media-dir if you do not intend to download assets (the default derives the directory from the output path).
  3. In scripts, only emit --media-dir when --media is also emitted.

Example fix

// before
dotnet run -- exportchat -c <id> -t <token> --media-dir ./assets
// after
dotnet run -- exportchat -c <id> -t <token> --media --media-dir ./assets
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrWhiteSpace(options.MediaDir) && !options.Media)
    throw new ArgumentException("--media-dir requires --media.");

Prevention

When it happens

Trigger: Running any export subcommand with `--media-dir <path>` while --media is not set. The guard `!string.IsNullOrWhiteSpace(AssetsDirPath) && !ShouldDownloadAssets` at ExportCommandBase.cs:163 fires during ExportAsync validation.

Common situations: Pre-configuring an output directory for assets in a script before enabling downloads; copy-pasting a config block that references --media-dir but drops --media; GUI-to-CLI translation where the media checkbox was left off.

Related errors


AI-assisted analysis of Tyrrrz/DiscordChatExporter@f6865c8216 (2026-08-13). Data as JSON: /api/errors/9876703f5ec1057e. Report an issue: GitHub.