Discordchatexporter: [CLI] Exclude Channels from Guild Export

Created on 2 Apr 2020  路  3Comments  路  Source: Tyrrrz/DiscordChatExporter

Could you add a option to the CLI when using exportguild, that allows you to list channels not to export? Thanks

enhancement wontfix

Most helpful comment

Windows script!
You might need to enable unsigned scripts execution before running the .ps1 file.
Create a filename.ps1 file in powershell_ise.exe (馃憟 recommended) or Notepad with the following content:

# \/ Replace this with DCE's directory.
cd C:\path\to\dcecli\folder

$TOKEN = "yourtokenhere"
$TOKENTYPE = "bot/user"
$SERVERID = "serveridhere"
$FORMAT = "htmldark/htmllight/plaintext/csv/json"
# /\ Choose only ONE format
# Don't forget to replace the "EXCLUDE" options below!

# \/ This checks if you've typed "bot" in the TOKENTYPE option
If($TOKENTYPE -match "bot"){$ISBOTYES = "-b"}
Else{$ISBOTYES = ""}

# \/ This will save the channels output to a file
.\DiscordChatExporter.Cli.exe channels -t $TOKEN $ISBOTYES -g $SERVERID | Out-File -filepath channels.tmp

<# \/ Replace "EXCLUDE1/2/3" with a channel name or ID you'd like to remove from the file.
If you want to exclude more channels, add more "Select-String -Pattern 'EXCLUDE' -NotMatch |" before the ) in the end of the command.
Please note that the last "Select-String -Pattern 'EXCLUDE' -NotMatch" must NOT have a | in its end #>
Set-Content -Path "channels.tmp" -Value (get-content -Path "channels.tmp" | Select-String -Pattern 'EXCLUDE1' -NotMatch | Select-String -Pattern 'EXCLUDE2' -NotMatch | Select-String -Pattern 'EXCLUDE3' -NotMatch)

# \/ This gets the first word from a line and sets it to the $Channel variable and keeps repeating it with the export command until the file ends
Get-Content 'channels.tmp' | ForEach-Object -Process {
    Set-Variable "Channel" ($_ -split ' ')[0]
    .\DiscordChatExporter.Cli.exe export -t $TOKEN $ISBOTYES -c $Channel -f $FORMAT
}
# \/ This removes the remaining .tmp file
rm channels.tmp -fo
exit 

Both scripts are very basic and can be improved, but they still work regardless.

All 3 comments

The command would be huge with a large amount of channels, but it sure is an interesting feature.

DiscordChatExporter.Cli.exe exportguild -t asdadsdsdadasdadadadasdsadadsadasdasdadadasdsadasdadasdsadadadasdads -g 592906419838124078 --exclude "535554350261469188, 664649014347825167, 623708173651673183, 535652743688355879, 694348184985796659"

If you won't be doing this very often and depending on the amount of channels to exclude, maybe the GUI is a better alternative.
#
While not as practical as a native DCE feature would be, you can also achieve this with the channels option and a simple script.
Basically, save the channels output to a file, remove the lines that contains the undesired channels, remove the | Channel name, repeat exportfor every line in the file.

I don't have one for Windows right now, I might do it later if I have some spare time. But I had made this one for macOS and it probably works on Linux:

#!/bin/bash
# \/ This will cd to the script's directory. You can replace ""${0%/*}" || exit" with DCE's directory if you'd like.
cd "${0%/*}" || exit

TOKEN=yourtokenhere
TOKENTYPE=bot/user
SERVERID=serveridhere
FORMAT=htmldark/htmllight/plaintext/csv/json
# /\ Choose only ONE format
# Don't forget to replace the "EXCLUDE" options below!

# \/ This checks if you've typed "bot" in the TOKENTYPE option
if [[ "$TOKENTYPE" == "bot" ]]; then
ISBOTYES=-b
fi

# \/ This will save the channels output to a file
dotnet DiscordChatExporter.Cli.dll channels -t ${TOKEN//\"} $ISBOTYES -g $SERVERID > channels.tmp

# \/ Replace "EXCLUDE1" with a channel name or ID you'd like to remove from the file, don't touch the "mv". 
awk '!/EXCLUDE1/' channels.tmp > awkchannels.tmp && mv awkchannels.tmp channels.tmp

# To exclude more than one channel, add more awks. Example to exclude 2 more channels. Remove the #s for them to run.
# awk '!/EXCLUDE2/' channels.tmp > awkchannels.tmp && mv awkchannels.tmp channels.tmp
# awk '!/EXCLUDE3/' channels.tmp > awkchannels.tmp && mv awkchannels.tmp channels.tmp

# \/ This command removes the '| Channel name`
cut -d' ' -f1 channels.tmp > cutchannels.tmp && mv cutchannels.tmp channels.tmp

# \/ This gets the content from a line and sets it to the $Channel variable and keeps repeating it  with the export command until the file ends
while read -r Channel
do
    if ! dotnet DiscordChatExporter.Cli.dll export -t ${TOKEN//\"} $ISBOTYES -c $Channel -f $FORMAT; then
      echo "Something went wrong while trying to export a server channel."
      exit
    fi
done <cutchannels.tmp

# \/ This removes the remaining .tmp file
if ! rm -Rf "channels.tmp"; then
echo "Unable to delete channels.tmp."
fi
exit

Windows script!
You might need to enable unsigned scripts execution before running the .ps1 file.
Create a filename.ps1 file in powershell_ise.exe (馃憟 recommended) or Notepad with the following content:

# \/ Replace this with DCE's directory.
cd C:\path\to\dcecli\folder

$TOKEN = "yourtokenhere"
$TOKENTYPE = "bot/user"
$SERVERID = "serveridhere"
$FORMAT = "htmldark/htmllight/plaintext/csv/json"
# /\ Choose only ONE format
# Don't forget to replace the "EXCLUDE" options below!

# \/ This checks if you've typed "bot" in the TOKENTYPE option
If($TOKENTYPE -match "bot"){$ISBOTYES = "-b"}
Else{$ISBOTYES = ""}

# \/ This will save the channels output to a file
.\DiscordChatExporter.Cli.exe channels -t $TOKEN $ISBOTYES -g $SERVERID | Out-File -filepath channels.tmp

<# \/ Replace "EXCLUDE1/2/3" with a channel name or ID you'd like to remove from the file.
If you want to exclude more channels, add more "Select-String -Pattern 'EXCLUDE' -NotMatch |" before the ) in the end of the command.
Please note that the last "Select-String -Pattern 'EXCLUDE' -NotMatch" must NOT have a | in its end #>
Set-Content -Path "channels.tmp" -Value (get-content -Path "channels.tmp" | Select-String -Pattern 'EXCLUDE1' -NotMatch | Select-String -Pattern 'EXCLUDE2' -NotMatch | Select-String -Pattern 'EXCLUDE3' -NotMatch)

# \/ This gets the first word from a line and sets it to the $Channel variable and keeps repeating it with the export command until the file ends
Get-Content 'channels.tmp' | ForEach-Object -Process {
    Set-Variable "Channel" ($_ -split ' ')[0]
    .\DiscordChatExporter.Cli.exe export -t $TOKEN $ISBOTYES -c $Channel -f $FORMAT
}
# \/ This removes the remaining .tmp file
rm channels.tmp -fo
exit 

Both scripts are very basic and can be improved, but they still work regardless.

Thanks for this, I've tested and works as intended.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

billyon picture billyon  路  3Comments

CyberneticSquid picture CyberneticSquid  路  3Comments

NNNIIndia picture NNNIIndia  路  4Comments

Latias4Ever picture Latias4Ever  路  4Comments

ealgase picture ealgase  路  4Comments