Closed ghost closed 2 years ago
oh, Sorry for my bad English. I am a Japanese student :(
It seems that you're passing a string value as timeout
, which is supposed to be a number.
This happens on your line 39, where you're initializing the JavaServer with server = JavaServer.lookup(arg1, arg2)
, and arg2
is apparently a string, instead of a timeout number. A valid call would look like this: JavaServer("mc.hypixel.net", 3)
, which would look up a server on mc.hypixel.net
address with 3 second maximum lookup duration.
You can omit the duration entirely as it is 3 by default, unless you'd need to change it explicitly for some reason.
I would however suggest that you use server = await JavaServer.async_lookup(...)
instead of the synchronous lookup
, to allow your bot to do other things while the server is being obtained, same goes for your calls to ping
, which should be await server.async_ping()
and query -> await server.async_query()
.
Thank you for your quick reply. I was able to solve the problem by converting to int type. Thank you! But I am stumped by the error that the server did not respond with any information. What should I do?
@lunar-night Are you seeing this? #316
But I am stumped by the error that the server did not respond with any information.
That just means the server is probably offline, or that mcstatus doesn't support it's version. If you've encountered this error on calling query
, know that most minecraft servers don't support query protocol by default, it's something that needs to be specifically enabled in server.properties
configuration file of the MC server.
I'd suggest wrapping the query
call, as well as the ping call into try-except
to handle for servers which aren't running, and servers which don't support query (which again, will be most servers).
You may want to use JavaServer.async_status
instead of query, status will run on pretty much any minecraft server unless it's too old (mcstatus doesn't support it), or is somehow customized to alter the status it returns (with some custom plugin), but that's very rare.
The status protocol is what minecraft clients use to display info about the server on the multiplayer server list screen. It includes the server description and number of online players, and server slot amount, and even some version info. Here' an example of using status:
Thanks.
But the error came up again..
2022-06-21T14:08:40.993804+00:00 app[final-bot.1]: An exception has occurred while executing command
status: 2022-06-21T14:08:40.993814+00:00 app[final-bot.1]: Traceback (most recent call last): 2022-06-21T14:08:40.993815+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord_slash/client.py", line 1352, in invoke_command 2022-06-21T14:08:40.993816+00:00 app[final-bot.1]: await func.invoke(ctx, **args) 2022-06-21T14:08:40.993816+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord_slash/model.py", line 210, in invoke 2022-06-21T14:08:40.993816+00:00 app[final-bot.1]: return await self.func(*args, **kwargs) 2022-06-21T14:08:40.993817+00:00 app[final-bot.1]: File "/app/src/main.py", line 44, in status_command 2022-06-21T14:08:40.993817+00:00 app[final-bot.1]: server = await JavaServer.async_status(address) 2022-06-21T14:08:40.993817+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/mcstatus/server.py", line 135, in async_status 2022-06-21T14:08:40.993818+00:00 app[final-bot.1]: await connection.connect(self.address, self.timeout) 2022-06-21T14:08:40.993818+00:00 app[final-bot.1]: AttributeError: 'str' object has no attribute 'address'
It might be easier to discuss further issues in our discord, here's an invite link: https://discord.gg/36tvX6EGFT
However the issue in your case is that you accidentally used async_status
to initialize the server, instead of async_lookup
:
server = await JavaServer.async_status(address) # Wrong
server = await JavaServer.async_lookup(address) # Do this instead
Thanks! It worked thanks to you! And I would like to join your discord server as well.
Dear mcstatus.
I have been avile for the past few days on a bot that can get the status of Minecraft servers using heroku & discord.py & mcstatus. But an error occurs...
main.py link
2022-06-21T09:13:20.957947+00:00 app[final-bot.1]: Traceback (most recent call last): 2022-06-21T09:13:20.957948+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord_slash/client.py", line 1352, in invoke_command 2022-06-21T09:13:20.957949+00:00 app[final-bot.1]: await func.invoke(ctx, **args) 2022-06-21T09:13:20.957949+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/discord_slash/model.py", line 210, in invoke 2022-06-21T09:13:20.957950+00:00 app[final-bot.1]: return await self.func(*args, **kwargs) 2022-06-21T09:13:20.957951+00:00 app[final-bot.1]: File "/app/src/main.py", line 39, in status_command 2022-06-21T09:13:20.957951+00:00 app[final-bot.1]: server = JavaServer.lookup(arg1, arg2) 2022-06-21T09:13:20.957952+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/mcstatus/server.py", line 57, in lookup 2022-06-21T09:13:20.957952+00:00 app[final-bot.1]: addr = minecraft_srv_address_lookup(address, default_port=25565, lifetime=timeout) 2022-06-21T09:13:20.957956+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/mcstatus/address.py", line 198, in minecraft_srv_address_lookup 2022-06-21T09:13:20.957957+00:00 app[final-bot.1]: answers = dns.resolver.resolve("_minecraft._tcp." + host, RdataType.SRV, lifetime=lifetime) 2022-06-21T09:13:20.957957+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/dns/resolver.py", line 1193, in resolve 2022-06-21T09:13:20.957958+00:00 app[final-bot.1]: return get_default_resolver().resolve(qname, rdtype, rdclass, tcp, source, 2022-06-21T09:13:20.957958+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/dns/resolver.py", line 1066, in resolve 2022-06-21T09:13:20.957958+00:00 app[final-bot.1]: timeout = self._compute_timeout(start, lifetime, 2022-06-21T09:13:20.957959+00:00 app[final-bot.1]: File "/app/.heroku/python/lib/python3.10/site-packages/dns/resolver.py", line 878, in _compute_timeout 2022-06-21T09:13:20.957959+00:00 app[final-bot.1]: if duration >= lifetime: 2022-06-21T09:13:20.957960+00:00 app[final-bot.1]: TypeError: '>=' not supported between instances of 'float' and 'str'
Python: 3.10.5 Discord.py: 1.7.3 mcstatus: 9.0.1Where did I go wrong? Please tell me Answer.