#đź”’ Help with Discord Webhook Integration and Username Checker Script

112 messages · Page 1 of 1 (latest)

acoustic sableBOT
#

@terse walrus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

terse walrus
#

Hey everyone!

I’ve been working on a Python script to check the availability of Minecraft usernames, and if a username is available, it pings me in a Discord channel. I’m using a Discord webhook to post the results of the checks.

Here’s a brief overview of the issue I’m facing:
Problem:

The script works as expected when checking usernames, but the message is not being sent to Discord, even though the script appears to execute without errors.

The webhook integration doesn’t seem to send messages or alerts as it should.

What I’ve Tried:

I’ve confirmed that the webhook URL is correct.

The check for username availability works, and the script logs the correct output for available/unavailable usernames in the console.

The issue seems to be related to the communication with Discord, as there is no error but no message is sent either.
lucid geode
#

What is userid used for

terse walrus
lucid geode
terse walrus
#

Because it's not my account

#

It's to ping my other discord account

lucid geode
#

Oh ok

terse walrus
#

Just don't want people friending it lols

#

Oh wait it seemed to work, It just doesn't do a live update.

#

It only sends the message when it's finished running the entire script and checking every name.

lucid geode
#

@terse walrus This is vibecoded right?

terse walrus
#

I'm not sure about 'vibecoded.' I wrote this script myself, but if you're referring to a specific style or method, I would love to know more!

lucid geode
terse walrus
#

Ohhh, no I wrote it myself and my friend tweaked a little bit of the code.

lucid geode
#

for username in usernames:
if username_is_available(username):

#

You used function which is not in the code

terse walrus
#

Oh what?

#

This is like my second time using python

lucid geode
terse walrus
#

I don't know what it means to look AI, I can ask my friend if she used AI? because i only did the first bit of the code.

lucid geode
#

Yeah ask

terse walrus
#

Okay!

#

She said she wrote it then cleaned it up with AI. whatever that means?

lucid geode
#

Cause idk using non-existing function is very ai job

lucid geode
terse walrus
#

The full script?

#

Sure

#

That bit is the only bit that seems to work as expected xD

acoustic sableBOT
#

Hey @terse walrus!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
lucid geode
#

Also i suggest using file to store the usernames

terse walrus
#

code block?

#

yea it does at the end

lucid geode
terse walrus
#

lemme re send that

#

ill upload to pastebin

#

discord does wacky shit with markdown

lucid geode
#

AI did very bad here, it removed the check account system through mojang API and included nonexistent function

lucid geode
lucid geode
terse walrus
#

it works yes

#

But only sends the message after the entire script has ran.

#

And I'm looking for it to send a message everytime it checks a name.

lucid geode
#

I think it actually does send

terse walrus
#

it does but only after it has checked every name in the txt

lucid geode
terse walrus
#

and with it containing like 20 thousand names, it is very painful to scroll up past all the existing names.

#

i wanna do the opposite

lucid geode
#

oh ok

terse walrus
#

make a list of non existent names

lucid geode
#

lemme see what i can do

terse walrus
#

okay awesome

lucid geode
#

can i remove comments from the code?

terse walrus
#

honestly it doesnt even need to send the unavailable names

indigo mirage
#

I do not recommend sending to discord due to message length and rate limit limitating

terse walrus
#

It will confuse me but yes sure

terse walrus
#

Sleep to avoid hitting rate limits or appearing like a bot

    time.sleep(1)
#

can discord stop formatting my messages

#

jeez

#

but yea it would be great if you could help with this

indigo mirage
#

e.g. it can only post message length <= 2000

terse walrus
#

yeah i know

lucid geode
#
# you can avoid formatting 
terse walrus
#

oh wow

#

yeah thats why i dont want it like this

indigo mirage
#

!d discord.utils.escape_markdown

acoustic sableBOT
#

discord.utils.escape_markdown(text, *, as_needed=False, ignore_links=True)```
A helper function that escapes Discord’s markdown.
terse walrus
#

i want it to either update live, or only send the available ones, which will only be like 1/1000 names

indigo mirage
lucid geode
#
import requests
import time
from colorama import Fore, Style, init

init()

WEBHOOK_URL = ""
USER_ID = ""

def check_username(username):
    url = f"https://api.mojang.com/users/profiles/minecraft/{username}"
    try:
        response = requests.get(url)
        return response.status_code == 204
    except requests.exceptions.RequestException as e:
        print(f"{Fore.RED}Error while checking username '{username}': {e}{Style.RESET_ALL}")
        return False

def send_to_discord(message):
    data = {"content": message}
    try:
        response = requests.post(WEBHOOK_URL, json=data)
        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}")

def check_and_send_usernames(filename):
    with open(filename, 'r') as file:
        usernames = file.readlines()

    for username in usernames:
        username = username.strip()
        print(f"{Fore.YELLOW}Checking username: {username}...{Style.RESET_ALL}")
        if check_username(username):
            print(f"{Fore.GREEN}Username '{username}' is available!{Style.RESET_ALL}")
            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}")
        time.sleep(1)

if __name__ == "__main__":
    check_and_send_usernames("usernames.txt")
#

Should work

terse walrus
#

let me try

#

works, however it doesnt send a live update

terse walrus
#

is that only possible with bot token?

#

i can see that

lucid geode
#

No, i made another program and it sends live

#

Without bot

terse walrus
#

oh where to?

#

wait im so stupid

#

i forgot to put my userid and webhook url back in there

#

dohhh

lucid geode
#

Should it also save them into a file?

terse walrus
#

doesnt need to if its sending to discord or somewhere else

#

works very well, but do you know how to do a live update?

#

sends each message individually so i can bulk search without running into the message limit

indigo mirage
#

Gonna try something that is faster

lucid geode
#
import requests
import time
from colorama import Fore, Style, init

init()

WEBHOOK_URL = ""
USER_ID = ""

def check_username(username):
    url = f"https://api.mojang.com/users/profiles/minecraft/{username}"
    try:
        response = requests.get(url)
        return response.status_code == 204
    except:
        return False

def send_to_discord(message):
    try:
        response = requests.post(WEBHOOK_URL, json={"content": message})
        if response.status_code == 204:
            print(f"{Fore.GREEN}Sent to Discord: {message}{Style.RESET_ALL}")
        else:
            print(f"{Fore.RED}Failed to send: {response.status_code} {response.text}{Style.RESET_ALL}")
    except Exception as e:
        print(f"{Fore.RED}Error sending to Discord: {e}{Style.RESET_ALL}")

def check_and_send_usernames(filename):
    with open(filename, 'r') as file:
        usernames = file.readlines()

    for username in usernames:
        username = username.strip()
        print(f"{Fore.YELLOW}Checking: {username}{Style.RESET_ALL}")
        if check_username(username):
            print(f"{Fore.GREEN}Available: {username}{Style.RESET_ALL}")
            send_to_discord(f"<@{USER_ID}> Username '{username}' is available!")
        else:
            print(f"{Fore.RED}Unavailable: {username}{Style.RESET_ALL}")
        time.sleep(1)

if __name__ == "__main__":
    check_and_send_usernames("usernames.txt")
terse walrus
lucid geode
#

You can use OpenBullet for that

#

Just make config yourself

terse walrus
#

yea

indigo mirage
terse walrus
#

600 requests per 10 minutes

indigo mirage
#

Have you checked? If so, where

terse walrus
#

thats mojang api

#
Minecraft Wiki

This page provides documentation for API endpoints provided by Mojang Studios which allows user to query player data and make changes programmatically.
Currently, the API is rate limited at 600 requests per 10 minutes.

#

discord is limited to 50 requests per second.

#

so the discord api is not a problem

indigo mirage
terse walrus
#

did it, but gonna have to heavily limit this, i can already see me getting limited by mojang

#

got it to work :D

indigo mirage
#

it should work if I didn't made mistake

acoustic sableBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.