├── LICENSE ├── README.md └── deleter ├── README.md ├── config.json ├── deleter.py └── requirements.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mohamed 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Discord scripts 2 | -------------------------------------------------------------------------------- /deleter/README.md: -------------------------------------------------------------------------------- 1 | A simple Discord chat deleter
2 | 3 | ### Config 4 | 5 | Configure `config.json` file. 6 | 7 | ### Get requirements 8 | 9 | 1. Open `https://discordapp.com/` in your browser 10 | 2. Login and enable developer mode on your Discord account 11 | 12 | ### How to get authorization token in Chrome 13 | 14 | 1. Press `f12` key on your keyboard 15 | 2. Click `Network` tab then `XHR` 16 | 3. Refresh page using `f5` key on your keyboard 17 | 4. Under `Name` tab click the `science` then `Headers` 18 | 5. Scroll through `Headers` until you find `authorization` then copy that into `config.json` 19 | 20 | ### How to get channel id in Chrome 21 | 22 | 1. Select the channel you wish to get the channel id of 23 | 2. Within the URL bar you should see something similar to: `https://discordapp.com/channels/@me/098765432109876543` 24 | 3. `098765432109876543` would be the channel id 25 | 26 | ### Admin user 27 | 28 | If the channel is a server and user has admin privs 29 | 30 | ### Install requirements 31 | 32 | ```shell 33 | $> pip install requirements.txt 34 | ``` 35 | 36 | ### Run 37 | 38 | ```shell 39 | $> python deleter.py 40 | ``` 41 | -------------------------------------------------------------------------------- /deleter/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "authorizationToken": "NTI5MzI1MzY4OTAyMDI1MjI3.DwvNFQ.5aNKUvYlAKqKKq6UJ1fRiARKNXQ", 3 | "channelID": "012345678901234567", 4 | "messageID": "098765432109876543", 5 | "isAdminUser": false 6 | } 7 | -------------------------------------------------------------------------------- /deleter/deleter.py: -------------------------------------------------------------------------------- 1 | # Date: 11/29/2019 2 | # Author: Mohamed 3 | # Description: A Simple Discord message deleter 4 | 5 | import time 6 | import json 7 | import requests 8 | 9 | 10 | config_file = 'config.json' 11 | 12 | 13 | class Deleter: 14 | 15 | api = 'https://discordapp.com/api/v6/channels' 16 | 17 | def __init__(self, auth_token, chan_id, latest_msg_id, is_admin_user): 18 | self.latest_msg_id = latest_msg_id 19 | self.base_url = f'{self.api}/{chan_id}/messages' 20 | 21 | self.user_id = None 22 | self.is_alive = True 23 | self.is_done = False 24 | self.chan_id = chan_id 25 | self.total_deleted = 0 26 | self.is_admin_user = is_admin_user 27 | 28 | self.headers = { 29 | 'Authorization': auth_token, 30 | 'content-type': 'application/json', 31 | } 32 | 33 | def get_user_id(self, msg_id): 34 | url = f'{self.base_url}/{msg_id}' 35 | 36 | try: 37 | resp = requests.patch(url, data=json.dumps({}), 38 | headers=self.headers).json() 39 | return resp['author']['id'] 40 | except: 41 | pass 42 | 43 | def get_messages(self): 44 | 45 | messages = [] 46 | url = f'{self.base_url}?before={self.latest_msg_id}&limit=100' 47 | 48 | if not self.is_admin_user and self.user_id == None: 49 | self.user_id = self.get_user_id(self.latest_msg_id) 50 | 51 | if not self.user_id: 52 | self.is_done = True 53 | return messages 54 | 55 | try: 56 | msgs = requests.get(url, headers=self.headers).json() 57 | 58 | for msg in msgs: 59 | msg_id = msg['id'] 60 | 61 | if not self.is_admin_user: 62 | if msg['author']['id'] == self.user_id: 63 | messages.append(msg_id) 64 | else: 65 | messages.append(msg_id) 66 | 67 | self.delete_msg(self.latest_msg_id) 68 | except: 69 | pass 70 | finally: 71 | if not messages: 72 | self.is_done = True 73 | 74 | return messages 75 | 76 | def delete_msg(self, msg_id: str): 77 | url = f'{self.base_url}/{msg_id}' 78 | 79 | try: 80 | requests.delete(url, headers=self.headers) 81 | self.total_deleted += 1 82 | 83 | print(f'Total messages deleted: {self.total_deleted:02}') 84 | time.sleep(0.5) 85 | except: 86 | pass 87 | 88 | def error_check(self): 89 | url = f'{self.api}/{self.chan_id}/messages?limit=1' 90 | r = requests.get(url, headers=self.headers).json() 91 | 92 | if 'code' in r: 93 | code = r['code'] 94 | 95 | if code == 0: 96 | print('Error: Invalid authorization token') 97 | exit() 98 | elif code == 10003: 99 | print('Error: Invalid channel id') 100 | exit() 101 | 102 | print(f'Error: {r["message"]}') 103 | exit() 104 | 105 | url = f'{self.base_url}/{self.latest_msg_id}' 106 | 107 | resp = requests.patch(url, data=json.dumps({}), 108 | headers=self.headers).json() 109 | 110 | if 'code' in resp: 111 | if resp['code'] == 10008: 112 | print('Error: Invalid message id') 113 | exit() 114 | 115 | def start(self): 116 | 117 | self.error_check() 118 | while self.is_alive and not self.is_done: 119 | messages = self.get_messages() 120 | 121 | if not messages: 122 | continue 123 | 124 | while len(messages) > 1: 125 | msg_id = messages.pop() 126 | self.delete_msg(msg_id) 127 | 128 | self.latest_msg_id = messages.pop() 129 | 130 | 131 | if __name__ == '__main__': 132 | 133 | with open(config_file, 'rt') as f: 134 | data = json.load(f) 135 | 136 | auth_token = data['authorizationToken'] 137 | channel_id = data['channelID'] 138 | message_id = data['messageID'] 139 | is_admin_user = data['isAdminUser'] 140 | 141 | Deleter(auth_token, channel_id, message_id, is_admin_user).start() 142 | -------------------------------------------------------------------------------- /deleter/requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.22.0 --------------------------------------------------------------------------------