Last active
April 3, 2025 03:24
-
-
Save stepney141/eedc8f48c9f7bd79d5a2ac1a602187dd to your computer and use it in GitHub Desktop.
A helper script to use DiscordChatExporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Info: https://github.com/Tyrrrz/DiscordChatExporter/blob/master/.docs | |
set -e | |
DLL_DIR_NAME='DiscordChatExporter.Cli.linux-x64' | |
LATEST_RELEASE="https://github.com/Tyrrrz/DiscordChatExporter/releases/latest/download/${DLL_DIR_NAME}.zip" | |
DLL_DIR_PATH="./${DLL_DIR_NAME}" | |
DCE="${DLL_DIR_PATH}/DiscordChatExporter.Cli" | |
if [ -z "$DISCORD_TOKEN" ]; then | |
echo "Error: DISCORD_TOKEN is not set. Please set it as an environment variable." | |
exit 1 | |
fi | |
# コマンドの存在チェック | |
if [ ! -x "$DCE" ]; then | |
echo "discord-chat-exporter is not installed or not executable. Downloading the latest releases..." | |
wget "$LATEST_RELEASE" -O "${DLL_DIR_NAME}.zip" | |
mkdir -p "${DLL_DIR_PATH}" | |
unzip "${DLL_DIR_NAME}.zip" -d "${DLL_DIR_PATH}" | |
chmod +x "$DCE" | |
rm "${DLL_DIR_NAME}.zip" | |
fi | |
# 引数チェック | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <GUILD_ID> <OUTPUT_DIR>" | |
echo "The GUILD_ID can be obtained by typing '${DCE} guilds --token <DISCORD_TOKEN>'." | |
exit 1 | |
fi | |
GUILD_ID="$1" | |
OUTPUT_DIR="$2" | |
mkdir -p "${OUTPUT_DIR}" | |
echo $(date +"%Y-%m-%d-%H-%M-%S") > "${OUTPUT_DIR}/DOWNLOADED_AT.txt" | |
download () { | |
local guild_id="$1" | |
local dir="$2" | |
local media_dir="${dir}/attached_assets" | |
mkdir -p "${media_dir}" | |
if ! "$DCE" exportguild --guild "$guild_id" --token "$DISCORD_TOKEN" --include-threads All --include-vc false --media --reuse-media --media-dir "${media_dir}" --output "${dir}/%T/%C.html"; then | |
echo "Error: Failed to download logs for guild $guild_id" | |
exit 1 | |
fi | |
} | |
download "$GUILD_ID" "$OUTPUT_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment