Dinnerbone / mcstatus

A Python class for checking the status of an enabled Minecraft server
http://dinnerbone.com/minecraft/tools/status/
1.11k stars 146 forks source link

Error message generated when running #129

Closed ko-cha closed 3 years ago

ko-cha commented 3 years ago
@bot.command()
async def server(ctx, ip):
    server = MinecraftServer.lookup(ip)
    status = server.status()
    embed = discord.Embed(title="Minecraftサーバーステータス情報", color=discord.Color.green())
    embed.add_field(name="<:right_arrow:793738556229156874>応答速度", value=f"{status.latency}ms")
    embed.add_field(name="<:right_arrow:793738556229156874>バージョン", value=f"{status.version.name}")
    embed.add_field(name="<:right_arrow:793738556229156874>オンライン人数", value=f"{status.players.online} / {status.players.max}")
    query = server.query()
    embed.add_field(name="<:right_arrow:793738556229156874>参加者", value="The server has the following players online: {0}".format(", ".join(query.players.names)))
    await ctx.send(embed=embed)

If you do this, you will get the following error

`The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: timeout: timed out`
Iapetus-11 commented 3 years ago

Learn how to read error messages. Timed out means mcstatus timed out whilst attempting to connect to the server, meaning the server is most likely offline. In addition, you shouldn't be using non-async blocking methods like those in asynchronous code, as it will prevent multiple events/commands/tasks from going on at once in your code.

ko-cha commented 3 years ago

Is this a problem within the Minecraft server? Or is it a problem with the code?

kevinkjt2000 commented 3 years ago

Presumably the line

status = server.status()

raised the timeout exception. You should consider using a try-catch block. Please consult a Python tutorial on how to catch exceptions.