Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- from colorama import Fore, Style, init
- # Initialize Colorama
- init()
- # Webhook URL (Your Discord webhook URL)
- WEBHOOK_URL = "" # Replace this with your webhook URL
- # Your Discord User ID (for pinging)
- USER_ID = "" # Your actual Discord User ID
- # Check username availability
- def check_username(username):
- url = f"https://api.mojang.com/users/profiles/minecraft/{username}"
- try:
- response = requests.get(url)
- if response.status_code == 204: # Username is available
- return True
- return False
- except requests.exceptions.RequestException as e:
- print(f"{Fore.RED}Error while checking username '{username}': {e}{Style.RESET_ALL}")
- return False
- # Function to send to Discord with a ping
- def send_to_discord(message):
- data = {
- "content": message
- }
- try:
- response = requests.post(WEBHOOK_URL, json=data)
- # Check the response status
- if response.status_code == 204:
- print(f"{Fore.GREEN}Message sent successfully to Discord!{Style.RESET_ALL}")
- else:
- print(f"{Fore.RED}Failed to send message. Status code: {response.status_code} Response: {response.text}{Style.RESET_ALL}")
- except Exception as e:
- print(f"{Fore.RED}Error while sending message to Discord: {e}{Style.RESET_ALL}")
- # Function to check all usernames in the text file and send available/unavailable ones to Discord
- def check_and_send_usernames(filename):
- available_usernames = []
- unavailable_usernames = []
- with open(filename, 'r') as file:
- usernames = file.readlines()
- for i, username in enumerate(usernames):
- username = username.strip() # Remove any leading/trailing whitespace
- print(f"{Fore.YELLOW}Checking username: {username}...{Style.RESET_ALL}")
- # Check if the username is available
- if check_username(username):
- print(f"{Fore.GREEN}Username '{username}' is available!{Style.RESET_ALL}")
- available_usernames.append(username)
- # Ping the user on Discord when an available username is found
- message = f"<@{USER_ID}> Username '{username}' is available!"
- send_to_discord(message)
- else:
- print(f"{Fore.RED}Username '{username}' is not available.{Style.RESET_ALL}")
- unavailable_usernames.append(username)
- # Sleep to avoid hitting rate limits or appearing like a bot
- time.sleep(1)
- # Send available usernames to Discord
- if available_usernames:
- message = f"Available Minecraft usernames:\n" + "\n".join(available_usernames)
- send_to_discord(message)
- else:
- send_to_discord("No available usernames found.")
- # Send unavailable usernames to Discord
- if unavailable_usernames:
- message = f"Unavailable Minecraft usernames:\n" + "\n".join(unavailable_usernames)
- send_to_discord(message)
- # Run the script with the text file of usernames
- if __name__ == "__main__":
- # Specify your text file containing usernames
- check_and_send_usernames("usernames.txt") # Replace with your actual file path
Advertisement
Add Comment
Please, Sign In to add comment