-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
86 lines (77 loc) · 4.02 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
import discord
from dotenv import load_dotenv
from mcstatus import *
from datetime import *
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
motd = [ motdtext['text'] for motdtext in status.raw['description']['extra']]
#print(usersConnected)
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="your commands."))
#print(status.raw)
@client.event
async def on_message(message):
if message.author == client.user:
return
try:
server = MinecraftServer.lookup("142.44.135.67:25575")
except Exception:
auth = str(message.author).split("#")
dt = str(datetime.now()).split()
embed = discord.Embed(title="Error",colour=discord.Colour.red())
embed.add_field(name="~~~~~~~~~~~~~~~~~~~~",value="The server doesn't seem to be online.")
embed.set_thumbnail(url="https://media.discordapp.net/attachments/775408277616853075/779091594955587584/logoisgood.gif")
embed.set_footer(text=str(auth[0])+" • "+str(dt[0]))
await message.channel.send(embed=embed)
return
if message.content == 'sninfo':
status = server.status()
try:
usersConnected = [ user['name'] for user in status.raw['players']['sample'] ]
except KeyError:
usersConnected = ["None"]
auth = str(message.author).split("#")
dt = str(datetime.now()).split()
embed = discord.Embed(title="Server Info",colour=discord.Colour.red())
embed.add_field(name="Server IP",value="`142.44.135.67:25575`",inline=False)
embed.add_field(name="# of Players Online",value="`"+str(status.players.online)+"/"+str(status.players.max)+"`",inline=False)
embed.add_field(name="Players Online",value="`"+"`, `".join(usersConnected)+"`",inline=False)
embed.set_thumbnail(url="https://media.discordapp.net/attachments/775408277616853075/779091594955587584/logoisgood.gif")
embed.set_footer(text=str(auth[0])+" • "+str(dt[0]))
await message.channel.send(embed=embed)
elif message.content == 'pplonline':
status = server.status()
try:
usersConnected = [ user['name'] for user in status.raw['players']['sample'] ]
except KeyError:
usersConnected = ["None"]
auth = str(message.author).split("#")
dt = str(datetime.now()).split()
embed = discord.Embed(title="People Online",colour=discord.Colour.red())
embed.add_field(name='~~~~~~~~~~~~~~~~~~~~',value="`"+"`, `".join(usersConnected)+"`",inline=False)
embed.set_thumbnail(url="https://media.discordapp.net/attachments/775408277616853075/779091594955587584/logoisgood.gif")
embed.set_footer(text=str(auth[0])+" • "+str(dt[0]))
await message.channel.send(embed=embed)
elif message.content == 'snversion':
status = server.status()
auth = str(message.author).split("#")
dt = str(datetime.now()).split()
embed = discord.Embed(title="Server Version",colour=discord.Colour.red())
embed.add_field(name='~~~~~~~~~~~~~~~~~~~~',value="`"+str(status.version.name)+"`",inline=False)
embed.set_thumbnail(url="https://media.discordapp.net/attachments/775408277616853075/779091594955587584/logoisgood.gif")
embed.set_footer(text=str(auth[0])+" • "+str(dt[0]))
await message.channel.send(embed=embed)
elif message.content == 'snmotd':
status = server.status()
auth = str(message.author).split('#')
dt = str(datetime.now()).split()
embed = discord.Embed(title="Server MOTD",colour=discord.Colour.red())
embed.add_field(name='~~~~~~~~~~~~~~~~~~~~',value="`"+str(motd[0])+"`",inline=False)
embed.set_thumbnail(url="https://media.discordapp.net/attachments/775408277616853075/779091594955587584/logoisgood.gif")
embed.set_footer(text=str(auth[0])+" • "+str(dt[0]))
await message.channel.send(embed=embed)
client.run(TOKEN)