cedws / discord-delete

Tool to delete Discord message history
GNU General Public License v3.0
126 stars 18 forks source link

Discord API changes have partially broken message deletion #21

Closed larryqiann closed 4 years ago

larryqiann commented 4 years ago

It looks like many messages are being left behind when running the Go version - I have run it manually several times and each time it finishes with a significant number of messages remaining in threads. I know the tool is hitting them because newer messages are deleted, but there are a lot remaining. Is this an expected behaviour? The Python version worked correctly last I tried it,

cedws commented 4 years ago

Is this an expected behaviour?

It isn't, it should delete everything it can find on the first run. However, I have some ideas why this might be happening.

Are you using the latest release? And do you see any errors in the output? (pass -v if you aren't doing so already)

larryqiann commented 4 years ago

INFO[0048] Deleting message 647243810 from channel 647149098 DEBU[0048] DELETE https://discordapp.com/api/v6/channels/647**9098/messages/647**143810 DEBU[0048] Server returned status No Content
DEBU[0048] Skipping context message
DEBU[0048] Skipping context message
INFO[0048] Deleting message 6474855 from channel 647149098 DEBU[0048] DELETE https://discordapp.com/api/v6/channels/6471***98/messages/6472***855 DEBU[0048] Server returned status No Content
DEBU[0048] Skipping context message
DEBU[0048] Skipping context message
INFO[0048] Deleting message 64703 from channel 64719098 DEBU[0048] DELETE https://discordapp.com/api/v6/channels/64718***9098/messages/6472***4803 DEBU[0048] Server returned status Too Many Requests
INFO[0048] Server asked us to sleep for 518 milliseconds DEBU[0049] DELETE https://discordapp.com/api/v6/channels/6471***9098/messages/647***803 DEBU[0049] Server returned status No Content
DEBU[0049] Skipping context message
DEBU[0049] Skipping context message
INFO[0049] Deleting message 647888 from channel 64775 DEBU[0049] DELETE https://discordapp.com/api/v6/channels/647***875/messages/647***888 DEBU[0049] Server returned status No Content
DEBU[0049] GET https://discordapp.com/api/v6/guilds/643***24/messages/search?author_id=247***0945&include_nsfw=true&offset=0&limit=25 DEBU[0049] Server returned status OK
INFO[0049] No more messages to delete for guild '*****' larryqian@Larrys-MacBook-Pro Downloads %

This is what it looks like when it ends. No other errors are raised. I do get "No more messages to delete for $server" messages though.

cedws commented 4 years ago

Everything in the log seems normal. There's probably a bug with the message querying algorithm. Question: in the groups that it fails to clear all messages from, are there a lot of calls? Discord actually considers these messages but they have a different numeric type, so the code has to increment an offset when it finds these.

larryqiann commented 4 years ago

The failures are fairly well distributed, and are equally present in servers lacking a voice channel/calls altogether.

cedws commented 4 years ago

I'm able to reproduce this issue... it's not looking good. I think Discord have broken the way the program finds messages. Some queries are returning zero results.

Still looking for a solution.

larryqiann commented 4 years ago

Interestingly enough recently the only other Discord deletion app on GitHub also died in a similar way, with errors related to "Got an empty page from the server".

I noticed that on the webUI doing a search in a server for messages you sent sometimes didn't return results either. Clicking "next page" several times always returned results, and seems to just increment the offset by 25 each time. It looks like the search endpoint they are using is /guilds/55...76/messages/66...78/?author....but the official deletion api uses /channels.

cedws commented 4 years ago

Yep, their API is completely broken. It's returning empty pages and 500s all the time now. I hope this won't be a problem forever, because it makes this tool unusable. There's no way around it other than brute-force searching, which is only really practical for DMs.

I've just committed c61c7705665f57b0b6139516acc0ae25e9cbf09f which might help a bit, but really, the issue is on Discord's side. Not much that I can do. I will leave this issue open and hopefully we'll see them resolve this within the next few weeks.

Thanks for the report as always.

larryqiann commented 4 years ago

It looks like this new commit has resolved the problem and it was able to clear out everything it missed. Thanks!

With that said the way search works is definitely broken on their end. It still says that there are messages remaining and 20 pages, even though none of them are populated in the official app. Maybe it takes them a while to update that index.

blawar commented 4 years ago

I fixed this issue and posted a working script to highlight the fix.

The issue is that discord api is returning a positive number of results, but then the messages array is empty. This happens when you delete messages, however discord isnt updating its internal database properly and causes empty messages to be returned that must be skipped.

The solution is to first iterate to get all of the posts, and store them in your own array, then go back and run delete on those message's.

https://github.com/blawar/discordnuke/blob/master/discordnuke.js

cedws commented 4 years ago

Thanks, but the solution seems a bit over the top. All you need to do is increment the offset when you find an empty page. This was done in c61c7705665f57b0b6139516acc0ae25e9cbf09f.

zyrodos commented 4 years ago

hey @cedws i'm getting an error saying level=fatal msg="Error fetching messages for channel: Status code Not Found is unhandled" now, any idea how to get around this?

cedws commented 4 years ago

@zyrodos Happens for me too. It looks like another API update has broken the tool. I'll get back to you when there's a fix.

cedws commented 4 years ago

What on earth... search doesn't work in the client either. I think their API is outright broken. Try doing a message search in Discord. Do you see Uh... can you try searching again??

zyrodos commented 4 years ago

I am getting the same message when I try to search, yes. Interesting. @cedws

zyrodos commented 4 years ago

I just ran it a few times, and it only removed things from certain channels. It did not remove any DMs.

cedws commented 4 years ago

Yeah apparently this is a known ongoing issue. It may be a week or so before the results are fixed.

cedws commented 4 years ago

Just pushed release 1.1.5. Discord's backend appears to be fixed, and the API behaviour has reverted to how it was before 1.1.4.

Please upgrade to this release and let me know if you have any problems.