Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a minecraft server is online and get info of stats (like number of players online) using Discord py

I have a bot that works in a discord server for a minecraft server. I want to make one of the bot's command to ping the minecraft server to check if it is up (or even get stats like number of players).

Does anybody know of a way to ping a mc server and even get stats from said server?

like image 927
shnap Avatar asked Oct 28 '25 02:10

shnap


1 Answers

This is possible! You can use Dinnerbone's own implementation.

This basic Python script should do what you want (using hypixel as an example):

from mcstatus import MinecraftServer

server = MinecraftServer.lookup("mc.hypixel.net")
status = server.status()
print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))

latency = server.ping()
print("The server replied in {0} ms".format(latency))

There's heaps more you can do, check it out: https://github.com/Dinnerbone/mcstatus

You can install this package by running:

python3 -m pip install mcstatus

Also note that according to the Github repo, this will only work on servers above version 1.7 :)

like image 134
Lemon Avatar answered Oct 30 '25 18:10

Lemon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!