-
Notifications
You must be signed in to change notification settings - Fork 3
/
aternos_server_bot.py
54 lines (41 loc) · 1.51 KB
/
aternos_server_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import discord
import os
from python_aternos import Client
import time
TOKEN = 'paste-your-token-here'
client = discord.Client()
aternos = Client('your-aternos-username', password='your-aternos-password')
atservers = aternos.servers
myserv = atservers[0]
@client.event
async def on_ready():
print('we have logged in a {0.user}'.format(client))
@client.event
async def on_message(message):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel})')
if message.author == client.user:
return
if message.channel.name == 'bot-cmnds':
if user_message.lower() == '?hello':
await message.channel.send(f'Hello {username}!')
return
if message.channel.name == 'bot-cmnds':
if user_message.lower() == '?server_start':
myserv.start()
while True:
ping = str(os.popen('mcstatus yourservername.aternos.me status | grep description').read())
if "offline" in ping:
time.sleep(1)
else:
break
await message.channel.send("server is now alive!!! you can join in 2-3 minutes by pasting ||yourservername.aternos.me:serverport|| in the server address.")
return
if message.channel.name == 'bot-cmnds':
if user_message.lower() == '?server_stop':
myserv.stop()
await message.channel.send(f'server stopped')
return
client.run(TOKEN)