DarkCat09 / python-aternos

[UNMAINTAINED] Unofficial Aternos API written in Python
https://pypi.org/project/python-aternos/
Apache License 2.0
92 stars 12 forks source link

Couldn't start server #50

Closed Horizon6053 closed 2 years ago

Horizon6053 commented 2 years ago

i need help so it keep showing me this error whenever i use webserver

File "C:\Users\\Desktop\Python\Discord\Test.py", line 3, in <module>
    from webserver import keep_alive
  File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\site-packages\webserver\__init__.py", line 17, in <module>
    run_command(["sudo", "mkdir", "-p", f"/etc/webserver/{folder}"])
  File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 501, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

and i found a python script so i copied it and then i ofcourse configured it and then after that its working pretty fine without wbeserver but it keep saying "Server couldn't open" this is the code:

import discord
import python_aternos
import webserver
from discord.ext import commands
from python_aternos import Client
from webserver import keep_alive

token =''
client = commands.Bot(command_prefix='$', help_command=None)

@client.event
async def on_ready():
    print(f'Logged in as {client.user}')

@client.command()
async def start(ctx):
    try:
        aternos = Client.from_credentials("", "")

    except Exception as e:
        await ctx.send("Couldnt log in")
        await ctx.send(f"Error {e}")

    else:
        servs = aternos.list_servers()

        for serv in servs:
            if serv.address == 'HorizonSmpDNK.aternos.me:12584':
                myserver = serv

        try:
            myserver.start()
        except:
            await ctx.send("Server couldn't open.")
        else:
            await ctx.send('await ctx.send("SERVER SUCESSFULLY OPENED!\nServer Address: HorizonSmpDNK.aternos.me:12584\nPort: 12584")')

keep_alive()
client.run(token)

yes i copied the code but it isnt working pls respond i really need help i've been stuck...

this is my plan so basically on discord if someone typied $start the server will start but instead it will just say "Server couldn't open" i tried $start many times... pls respond :(

DarkCat09 commented 2 years ago
try:
    myserver.start()
except:
    await ctx.send("Server couldn't open.")

Please, replace this code with:

try:
    myserver.start()
except Exception as ex:
    print(ex)

And then, send me output.
In that case I'll find out which error do you have.
Maybe, myserver contains None so interpreter raises AttributeError.

DarkCat09 commented 2 years ago
if serv.address == 'HorizonSmpDNK.aternos.me:12584':

Also, I don't recommend comparing full address,
because Aternos can change the port or, for example, move to other domain.
Use if serv.subdomain == 'HorizonSmpDNK': ...

Horizon6053 commented 2 years ago

ill try to do that! thanks!

Horizon6053 commented 2 years ago

what do "local variable 'myserver' referenced before assignment" means...

Horizon6053 commented 2 years ago

import discord import python_aternos from discord.ext import commands from python_aternos import Client

token = '' client = commands.Bot(command_prefix='$', help_command=None)

@client.event async def on_ready(): print(f'Logged in as {client.user}')

@client.command() async def start(ctx): try: aternos = Client.from_credentials("", "")

except Exception as e:
    await ctx.send("Couldnt log in")
    await ctx.send(f"Error {e}")

else:
    servs = aternos.list_servers()

    for serv in servs:
        if serv.address == 'HorizonSmpDNK.aternos.me:12584':
            myserver = serv

    try:
        myserver.start()
    except Exception as ex:
        print(ex)
    else:
        await ctx.send('await ctx.send("SERVER SUCESSFULLY OPENED!\nServer Address: HorizonSmpDNK.aternos.me:12584\nPort: 12584")')

client.run(token)

DarkCat09 commented 2 years ago

You try to start server before creating variable myserver.
If condition always False (there's no server with that name) or for loop never starts (list_servers returns empty []), myserver won't be declared!

myserver = None
for s in at.list_servers():
  if s.subdomain == ...:
    myserver = s
if s is not None:
  myserver.start()
DarkCat09 commented 2 years ago

In your case, error caused by empty servers list.
It's a bug (#43 and #48), please, wait for a new version.