Created
April 18, 2023 11:18
-
-
Save py7hon/7fc0ee5d9a6a1e1068efa6d575ed9ba1 to your computer and use it in GitHub Desktop.
Revisions
-
py7hon created this gist
Apr 18, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ #how to use 1. put any file or voice with codec `audio/ogg` 2. fill `token` and `channel_id` on `config.json` 3. run `py main.py` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ { "token":"", "channel_id":"" } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ import os, json import requests import base64 voice_data = open(os.path.join(os.getcwd(), "voice-message.ogg"), "rb").read() def data(): file = json.load(open("config.json")) data = { "token":file["token"], "channel_id":file["channel_id"] } return data json_data = data() attach_url = f'https://discord.com/api/v10/channels/{json_data["channel_id"]}/attachments' attach_headers = { 'Content-Type': 'application/json', 'Authorization': json_data["token"] } attach_data = { 'files': [{ 'file_size': len(voice_data), 'filename': 'voice-message.ogg', 'id': '2' }] } attach_response = requests.post(attach_url, headers=attach_headers, data=json.dumps(attach_data)) attach_json = attach_response.json() upload_url = attach_json['attachments'][0]['upload_url'] upload_filename = attach_json['attachments'][0]['upload_filename'] upload_headers = {'Content-Type': 'audio/ogg'} print(requests.put(upload_url, headers=upload_headers, data=voice_data).text) message_url = f'https://discord.com/api/v10/channels/{json_data["channel_id"]}/messages' message_headers = { 'Content-Type': 'application/json', 'Authorization': json_data["token"], 'x-super-properties': 'eyJvcyI6IldpbmRvd3MiLCJjbGllbnRfYnVpbGRfbnVtYmVyIjo5OTk5OTk5fQ==' } message_data = { 'flags': 8192, 'attachments': [{ 'id': '0', 'filename': 'voice-message.ogg', 'uploaded_filename': upload_filename, 'duration_secs': 0.000001, 'waveform': base64.b64encode(voice_data[:100]).decode("utf-8") }] } print(requests.post(message_url, headers=message_headers, data=json.dumps(message_data)).status_code)