DiscordChatExporter/.docs/Using-the-CLI.md

279 lines
9.6 KiB
Markdown
Raw Normal View History

2023-09-29 07:53:52 -04:00
# Using the CLI
## Step 1
After extracting the `.zip`, open Command Prompt, aka `cmd` (`Terminal` on **macOS** and **Linux**).
## Step 2
2024-04-29 17:07:29 -04:00
Change the current directory to DCE's folder with `cd C:\path\to\DiscordChatExporter` (`cd /path/to/DiscordChatExporter` on **MacOS** and **Linux**), then press ENTER to run the command.
2023-09-29 07:53:52 -04:00
2024-04-29 17:07:29 -04:00
**Windows** users can quickly get the folder's path by clicking the address bar while inside the folder.
2023-09-29 07:53:52 -04:00
![Copy path from Explorer](https://i.imgur.com/XncnhC2.gif)
2024-04-29 17:07:29 -04:00
**macOS** users can press Command+Option+C (⌘⌥C) while inside the folder (or selecting it) to copy its path to the clipboard.
2023-09-29 07:53:52 -04:00
You can also drag and drop the folder on **every platform**.
![Drag and drop folder](https://i.imgur.com/sOpZQAb.gif)
## Step 3
2023-11-11 10:47:48 -05:00
Now we're ready to run the commands. The examples on this page follow the Windows file path format, change the file
paths according to your system.
2023-09-29 07:53:52 -04:00
Type the following command in your terminal of choice, then press ENTER to run it. This will list all available subcommands and options.
```console
$ ./DiscordChatExporter.Cli
2023-09-29 07:53:52 -04:00
```
2023-11-11 10:47:48 -05:00
> **Docker** users, please refer to the [Docker usage instructions](Docker.md).
2023-09-29 07:53:52 -04:00
## CLI commands
| Command | Description |
|-------------------------|------------------------------------------------------|
| export | Exports a channel |
| exportdm | Exports all direct message channels |
| exportguild | Exports all channels within the specified server |
| exportall | Exports all accessible channels |
| channels | Outputs the list of channels in the given server |
| dm | Outputs the list of direct message channels |
| guilds | Outputs the list of accessible servers |
| guide | Explains how to obtain token, server, and channel ID |
2023-11-22 17:16:36 -05:00
To use the commands, you'll need a token. For the instructions on how to get a token, please refer to [this page](Token-and-IDs.md), or run `./DiscordChatExporter.Cli guide`.
2023-11-22 17:16:36 -05:00
To get help with a specific command, run:
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli command --help
2023-09-29 07:53:52 -04:00
```
2023-11-22 17:16:36 -05:00
For example, to figure out how to use the `export` command, run:
2023-09-29 07:53:52 -04:00
2023-11-22 17:16:36 -05:00
```console
$ ./DiscordChatExporter.Cli export --help
2023-11-22 17:16:36 -05:00
```
2023-09-29 07:53:52 -04:00
2023-11-22 17:16:36 -05:00
## Export a specific channel
2023-09-29 07:53:52 -04:00
You can quickly export with DCE's default settings by using just `-t token` and `-c channelid`.
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555
2023-09-29 07:53:52 -04:00
```
#### Changing the format
2023-11-11 10:47:48 -05:00
You can change the export format to `HtmlDark`, `HtmlLight`, `PlainText` `Json` or `Csv` with `-f format`. The default
format is `HtmlDark`.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -f Json
2023-09-29 07:53:52 -04:00
```
#### Changing the output filename
You can change the filename by using `-o name.ext`. e.g. for the `HTML` format:
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -o myserver.html
2023-09-29 07:53:52 -04:00
```
#### Changing the output directory
2023-11-11 10:47:48 -05:00
You can change the export directory by using `-o` and providing a path that ends with a slash or does not have a file
extension.
2023-09-29 07:53:52 -04:00
If any of the folders in the path have a space in its name, escape them with quotes (").
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports"
2023-09-29 07:53:52 -04:00
```
#### Changing the filename and output directory
You can change both the filename and export directory by using `-o directory\name.ext`.
Note that the filename must have an extension, otherwise it will be considered a directory name.
If any of the folders in the path have a space in its name, escape them with quotes (").
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports\myserver.html"
2023-09-29 07:53:52 -04:00
```
#### Generating the filename and output directory dynamically
You can use template tokens to generate the output file path based on the server and channel metadata.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -o "C:\Discord Exports\%G\%T\%C.html"
2023-09-29 07:53:52 -04:00
```
2023-11-11 10:47:48 -05:00
Assuming you are exporting a channel named `"my-channel"` in the `"Text channels"` category from a server
called `"My server"`, you will get the following output file
path: `C:\Discord Exports\My server\Text channels\my-channel.html`
2023-09-29 07:53:52 -04:00
Here is the full list of supported template tokens:
- `%g` - server ID
- `%G` - server name
2023-09-29 07:53:52 -04:00
- `%t` - category ID
- `%T` - category name
- `%c` - channel ID
- `%C` - channel name
- `%p` - channel position
- `%P` - category position
- `%a` - the "after" date
- `%b` - the "before" date
- `%%` - escapes `%`
#### Partitioning
You can use partitioning to split files after a given number of messages or file size.
For example, a channel with 36 messages set to be partitioned every 10 messages will output 4 files.
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -p 10
2023-09-29 07:53:52 -04:00
```
A 45 MB channel set to be partitioned every 20 MB will output 3 files.
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 -p 20mb
2023-09-29 07:53:52 -04:00
```
#### Downloading assets
If this option is set, the export will include additional files such as user avatars, attached files, images, etc.
2023-11-11 10:47:48 -05:00
Only files that are referenced by the export are downloaded, which means that, for example, user avatars will not be
downloaded when using the plain text (TXT) export format.
2023-09-29 07:53:52 -04:00
A folder containing the assets will be created along with the exported chat. They must be kept together.
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --media
2023-09-29 07:53:52 -04:00
```
#### Reusing assets
2023-11-11 10:47:48 -05:00
Previously downloaded assets can be reused to skip redundant downloads as long as the chat is always exported to the
same folder. Using this option can speed up future exports. This option requires the `--media` option.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --media --reuse-media
2023-09-29 07:53:52 -04:00
```
#### Changing the media directory
2023-11-11 10:47:48 -05:00
By default, the media directory is created alongside the exported chat. You can change this by using `--media-dir` and
providing a path that ends with a slash. All of the exported media will be stored in this directory.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --media --media-dir "C:\Discord Media"
2023-09-29 07:53:52 -04:00
```
#### Changing the date format
2023-11-11 10:47:48 -05:00
You can customize how dates are formatted in the exported files by using `--locale` and inserting one of Discord's
locales. The default locale is `en-US`.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --locale "de-DE"
2023-09-29 07:53:52 -04:00
```
#### Date ranges
**Messages sent before a date**
Use `--before` to export messages sent before the provided date. E.g. messages sent before September 18th, 2019:
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --before 2019-09-18
2023-09-29 07:53:52 -04:00
```
**Messages sent after a date**
Use `--after` to export messages sent after the provided date. E.g. messages sent after September 17th, 2019 11:34 PM:
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --after "2019-09-17 23:34"
2023-09-29 07:53:52 -04:00
```
**Messages sent in a date range**
2023-11-11 10:47:48 -05:00
Use `--before` and `--after` to export messages sent during the provided date range. E.g. messages sent between
September 17th, 2019 11:34 PM and September 18th:
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli export -t "mfa.Ifrn" -c 53555 --after "2019-09-17 23:34" --before "2019-09-18"
2023-09-29 07:53:52 -04:00
```
2023-11-11 10:47:48 -05:00
You can try different formats like `17-SEP-2019 11:34 PM` or even refine your ranges down to
milliseconds `17-SEP-2019 23:45:30.6170`!
2023-09-29 07:53:52 -04:00
Don't forget to quote (") the date if it has spaces!
2023-11-11 10:47:48 -05:00
More info about .NET date
formats [here](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).
2023-09-29 07:53:52 -04:00
### Export channels from a specific server
2023-09-29 07:53:52 -04:00
To export all channels in a specific server, use the `exportguild` command and provide the server ID through the `-g|--guild` option:
2023-09-29 07:53:52 -04:00
2023-11-22 17:16:36 -05:00
```console
$ ./DiscordChatExporter.Cli exportguild -t "mfa.Ifrn" -g 21814
2023-11-22 17:16:36 -05:00
```
2023-09-29 07:53:52 -04:00
#### Including threads
2023-11-11 10:47:48 -05:00
By default, threads are not included in the export. You can change this behavior by using `--include-threads` and
specifying which threads should be included. It has possible values of `none`, `active`, or `all`, indicating which
threads should be included. To include both active and archived threads, use `--include-threads all`.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli exportguild -t "mfa.Ifrn" -g 21814 --include-threads all
2023-09-29 07:53:52 -04:00
```
#### Including voice channels
2023-11-11 10:47:48 -05:00
By default, voice channels are included in the export. You can change this behavior by using `--include-vc` and
specifying whether to include voice channels in the export. It has possible values of `true` or `false`, to exclude
voice channels, use `--include-vc false`.
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli exportguild -t "mfa.Ifrn" -g 21814 --include-vc false
2023-09-29 07:53:52 -04:00
```
2023-11-22 17:16:36 -05:00
### Export all channels
2023-09-29 07:53:52 -04:00
2023-11-22 17:16:36 -05:00
To export all accessible channels, use the `exportall` command:
```console
$ ./DiscordChatExporter.Cli exportall -t "mfa.Ifrn"
2023-11-22 17:16:36 -05:00
```
2023-09-29 07:53:52 -04:00
#### Excluding DMs
To exclude DMs, add the `--include-dm false` option.
```console
$ ./DiscordChatExporter.Cli exportall -t "mfa.Ifrn" --include-dm false
2023-09-29 07:53:52 -04:00
```
### List channels in a server
2023-09-29 07:53:52 -04:00
To list the channels available in a specific server, use the `channels` command and provide the server ID through the `-g|--guild` option:
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli channels -t "mfa.Ifrn" -g 21814
2023-09-29 07:53:52 -04:00
```
2023-11-22 17:16:36 -05:00
### List direct message channels
2023-09-29 07:53:52 -04:00
2023-11-22 17:16:36 -05:00
To list all DM channels accessible to the current account, use the `dm` command:
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli dm -t "mfa.Ifrn"
2023-09-29 07:53:52 -04:00
```
### List servers
2023-09-29 07:53:52 -04:00
To list all servers accessible by the current account, use the `guilds` command:
2023-09-29 07:53:52 -04:00
```console
$ ./DiscordChatExporter.Cli guilds -t "mfa.Ifrn" > C:\path\to\output.txt
2023-11-22 17:16:36 -05:00
```