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

Show parent comments

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!