Discord 的 Minecraft 服务器命令:“OSError:服务器没有响应任何信息!”

时间:2021-07-18 01:48:46

标签: python discord discord.py runtime-error minecraft

所以我正在尝试创建一个使用“discord.py”和“mcstatus”返回延迟和播放器编号的不和谐命令。每次运行命令时,我都会收到错误“OSError:服务器没有响应任何信息!”我尝试使用 MinecraftServer.lookup("mc.hypixel.net")MinecraftServer.lookup("mc.hypixel.net:25565")、{{1} },还有一些使用其他服务器,但它们都以相同的错误响应。

这是我的代码:

MinecraftServer("mc.hypixel.net", 25565)

1 个答案:

答案 0 :(得分:1)

问题在于 server.ping() 函数。 Tbh,我不知道为什么它不起作用,但它对我也不起作用。但令人高兴的是,延迟包含在 server.status() 调用中。


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))

我在我的机器上测试了这段代码,它完美无缺。 也许在 the github project of mcstats 上提出问题来解释问题。