py-mine / mcstatus

A Python library for checking the status of Minecraft servers
https://mcstatus.readthedocs.io
Apache License 2.0
472 stars 37 forks source link

Almost no servers return MOTD on ping #147

Closed py-mine-bot closed 2 years ago

py-mine-bot commented 2 years ago

j5155 Authored by j5155 Closed

I'm trying to make a python discord bot that pings servers using this library, but for some reason it only sends MOTD or description of the server for very few servers. My code:

@bot.command()
async def ping(ctx, ip):
    pingedServer = MinecraftServer.lookup(ip)

    try:
        status = pingedServer.status()
        await ctx.channel.send(f'{ip} has {status.players.online} players online and responded in {status.latency}ms. It runs {status.version.name}. \n MOTD: ```\n{str(status.description)}\n```')
    except:
        await ctx.channel.send('Server did not respond to request.')

When I ping most servers with this command (example: cubecraft.net), it returns

cubecraft.net has 6704 players online and responded in 101.289ms. It runs §cWe support: 1.12.2 - 1.17. 
 MOTD: 

but when I ping hypixel.net it returns

hypixel.net has 0 players online and responded in 92.341ms. It runs Requires MC 1.8 / 1.17. 
 MOTD: 
         §aHypixel Network  §c[Maintenance]
     §cFor More Information, §bhttps://hypixel.net

Is this an issue with the library or with my code? If it's my code, how can I fix this?

py-mine-bot commented 2 years ago

Iapetus-11 Authored by Iapetus-11


It appears to be an issue with how the library handles server motds. Some servers return a dictionary if the text has colors or other formatting in it, and the library just ignores all that.

https://github.com/Dinnerbone/mcstatus/blob/master/mcstatus/pinger.py#L207-L210

        if isinstance(raw["description"], dict):
            self.description = raw["description"]["text"]
        else:
            self.description = raw["description"]

I'll make and submit a PR soon!

py-mine-bot commented 2 years ago

kevinkjt2000 Authored by kevinkjt2000


Should be resolved in v6.4.0