So I'm trying to make a discord command that returns the latency and player numbers using "discord.py" and "mcstatus". Every time I run the command I get the error "OSError: Server did not respond with any information!" I've tried using MinecraftServer.lookup("mc.hypixel.net")
, MinecraftServer.lookup("mc.hypixel.net:25565")
, MinecraftServer("mc.hypixel.net", 25565)
, and some with other servers, but they all respond with the same error.
Here's my code:
import discord
import mcstatus
from mcstatus import MinecraftServer
from discord.ext import commands
client = commands.Bot(command_prefix='\\')
client.remove_command('help')
@client.event
async def on_ready():
activity = discord.Activity(type=discord.ActivityType.watching, name="for \\\'s")
await client.change_presence(status=discord.Status.online, activity=activity)
print('Logged in as {0.user}'.format(client))
@client.event
async def on_command_error(ctx, error):
print(error)
@client.command()
async def mcserver(ctx):
server = MinecraftServer.lookup("mc.hypixel.net")
status = server.status()
latency = server.ping()
print("The server replied in {0} ms".format(latency))
await ctx.channel.send("The server has {0} players and replied in {1}
ms".format(status.players.online, status.latency))
The problem lies in the server.ping()
function. Tbh, I don't know why its not working, but it isn't working for me either. But happily, the latency is included in the server.status()
call.
import discord
import mcstatus
from mcstatus import MinecraftServer
from discord.ext import commands
client = commands.Bot(command_prefix='\\')
client.remove_command('help')
@client.event
async def on_ready():
activity = discord.Activity(type=discord.ActivityType.watching, name="for \\\'s")
await client.change_presence(status=discord.Status.online, activity=activity)
print('Logged in as {0.user}'.format(client))
@client.event
async def on_command_error(ctx, error):
print(error)
@client.command()
async def mcserver(ctx):
server = MinecraftServer.lookup("mc.hypixel.net")
status = server.status()
print("The server replied in {0} ms".format(status.latency))
await ctx.channel.send("The server has {0} players and replied in {1}
ms".format(status.players.online, status.latency))
I tested this code on my machine, and it works flawlessly. Maybe make an issue on the github project of mcstats explaining the issue.