v2 (discontinued)
API Discontinued
This API version is discontinued, it's advised you use gRPC.
Export Formats Enum
Type | ID | Description | File Extension |
---|---|---|---|
PlainText | 0 | Export to a plaintext file | txt |
HtmlDark | 1 | Export to an HTML file in dark mode | html |
HtmlLight | 2 | Export to an HTML file in light mode | html |
CSV | 3 | Export to a comma separated values file | csv |
JSON | 4 | Export to a JSON file | json |
POST
/v2/export
Exports a channel. On success, it returns a file stream.
JSON Body
Field | Type | Description |
---|---|---|
token | string | The bot token for performing requests |
channel_id | string | The id of the channel to export |
export_format | ?ExportFormat | The format to export the channel as, defaults to HtmlDark |
date_format | ?string | The date format for dates in exported files, defaults to dd-MMM-yy hh:mm tt |
after | ?string | Only include messages sent after this date |
before | ?string | Only include messages sent before this date |
Examples
Typescript:
import fetch from 'node-fetch';
async function exportChannel(channel_id: string, token: string): Promise<Buffer> {
const response = await fetch('http://exportapi:80/v2/export', {
method: 'POST',
body: JSON.stringify({ channel_id, token }),
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
return response.buffer();
}
throw Error('Channel export failed!');
}
Rust
// reqwest = { version = "0.10", features = ["json"] }
use reqwest::Client;
use std::collections::HashMap;
use std::io::copy;
use std::fs::File;
async fn export_channel(channelId: &str, token: &str) -> Result<File, reqwest::Error> {
let client = Client::new();
let mut map = HashMap::new();
map.insert("channel_id", "channel id");
map.insert("token", "discord token");
let file = client.post("http://exportapi:80/v2/export").json(&map).await?.text().await?;
let dest = File::create("myexport.html")?;
copy(&mut file.as_bytes(), &mut dest)?;
Ok(dest)
}