r/pythonhelp • • Jan 07 '22

Why Is This Not Working

I'm trying to make a script that pings a Minecraft Server (using inputs) every little bit, so the server always stays online. But there are a few errors and I don't know why. I've only been using Python for a few Months.

import time
from mcstatus import MinecraftServer
print("Minecraft Server Pinger")
print("By:  ViridianTelamon.")
print("The Server Will Be Pinged Every 5 Minutes Until You Close This Script.")
Server = input("Enter Your Minecraft Java Server IP (Example:  Server.aternos.me):  ")
Port = input("Enter Your Minecraft Java Port Or Host (Example: 12345678910):  ")
Seconds = int(input("Enter The Amount Of Seconds For Intervals Between Server Pings:  "))
while True:
    time.sleep(280)
    server = MinecraftServer.lookup(Server,":",Port)
    latency = server.ping()
    print(f"The server replied in {latency} ms")

3 Upvotes

15 comments sorted by

View all comments

1

u/Vicente_Cunha Jan 07 '22

put the time.sleep below the print statement, because your script now waits 5 minutes and only then displays the data

1

u/ViridianGuy Jan 07 '22

I know, but afterwards (after the 5 minutes) it shows some error, I see it that fixes it though.

1

u/dagdag100 Jan 08 '22

post the new the error that your getting

1

u/ViridianGuy Jan 08 '22

File "c:\Users\Test_User\OneDrive\Desktop\Minecraft Server Pinger.py", line 22, in <module>

server = MinecraftServer.lookup(Server,":",Port)

TypeError: MinecraftServer.lookup() takes 2 positional arguments but 4 were given

1

u/dagdag100 Jan 08 '22

Try this 'MinecraftServer.lookup(Server, Port)" and if that doesn't work try this 'MinecraftServer.lookup(Server + ":" + Port)"

2

u/ViridianGuy Jan 08 '22

It works! Tysm! :)

1

u/dagdag100 Jan 08 '22

Np man keep doing you!