Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FeraruSilviuMarian/5da04c5dffb5308c9a558f0a5483ffa5 to your computer and use it in GitHub Desktop.
Save FeraruSilviuMarian/5da04c5dffb5308c9a558f0a5483ffa5 to your computer and use it in GitHub Desktop.
"""
1. your username is what you use, your full username including the #id can be found by clicking your name
2. authentification token can be found by going to discord on chrome (or other browsers), press F12, go to network tab, headers tab,
under request headers there is an "authetification", copy that.
3. Right click a channel and click copy id, paste it in the script
"""
import json, requests, sys
print ("Delete all messages from specific channel")
# Fill the following information
username1 = "yourusername"
username2 = "youruser#0000"
auth_token = "authetification" # see readme
channel_id = "thechannelid"
delete_from_all_users = "False"
def get_all_messages(auth, id, last="", prev=[]):
if not last:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"limit": 100}).content)
else:
messages = json.loads(requests.get("http://canary.discordapp.com/api/v6/channels/" + id + "/messages", headers={"authorization": auth}, params={"before" : last, "limit" : 100}).content)
print("messages:", messages)
#prev = prev + messages
if len(messages) < 100:
print ("Got to end of channel at " + str(len(prev)) + " messages")
return prev
else:
oldest = sorted(messages, key=lambda x: x["timestamp"], reverse=True)[-1]
return get_all_messages(auth, id, last=oldest["id"], prev=prev)
def delete_all(auth, id, user1, user2, messages):
print ("Trying to delete all messages in " + id + " from username " + user1)
for message in messages:
# print(message["author"]["username"])
if (message["author"]["username"] == user1):
requests.delete("http://canary.discordapp.com/api/v6/channels/" + id + "/messages/" + message["id"],headers={"authorization": auth})
print("Message with id: " + message["id"] + " deleted")
print ("All messages were deleted")
delete_all(auth_token, channel_id, username1, username2, get_all_messages(auth_token, channel_id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment