Minecraft server command for Discord: "OSError: Server did not respond with any information!"
Minecraft server command for Discord: "OSError: Server did not respond with any information!"
所以我正在尝试使用“discord.py”和“mcstatus”制作一个 returns 延迟和玩家数量的不和谐命令。每次我 运行 命令我得到错误“OSError:服务器没有响应任何信息!”我试过使用 MinecraftServer.lookup("mc.hypixel.net")
,MinecraftServer.lookup("mc.hypixel.net:25565")
、MinecraftServer("mc.hypixel.net", 25565)
,还有一些与其他服务器,但它们都以相同的错误响应。
这是我的代码:
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))
问题出在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 上提出一个问题来解释这个问题。
所以我正在尝试使用“discord.py”和“mcstatus”制作一个 returns 延迟和玩家数量的不和谐命令。每次我 运行 命令我得到错误“OSError:服务器没有响应任何信息!”我试过使用 MinecraftServer.lookup("mc.hypixel.net")
,MinecraftServer.lookup("mc.hypixel.net:25565")
、MinecraftServer("mc.hypixel.net", 25565)
,还有一些与其他服务器,但它们都以相同的错误响应。
这是我的代码:
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))
问题出在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 上提出一个问题来解释这个问题。