-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (38 loc) · 1.49 KB
/
app.py
File metadata and controls
44 lines (38 loc) · 1.49 KB
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
import classes
import asyncio
from discord.ext import commands
import discord
from pathlib import Path
parent_path = Path(__file__).parent
if parent_path.joinpath("Token").exists():
with open(parent_path.joinpath("Token"), "r") as file:
token = file.read().strip()
else:
raise FileNotFoundError("Token file not found.")
servername = "test67.valksystems.pro"
server = classes.MinecraftServerStatus(servername, update_interval=20)
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("Command not found. Use !help for a list of commands.")
async def update_status():
await bot.wait_until_ready()
while not bot.is_closed():
try:
status = server.is_online()
print(status)
if status:
activity = discord.Game(f"Active Players: {server.current_players()}/{server.max_players()}")
await bot.change_presence(status=discord.Status.online, activity=activity)
else:
await bot.change_presence(status=discord.Status.do_not_disturb, activity=discord.Game("Server is offline"))
except Exception as e:
print(f"Error updating status: {e}")
await asyncio.sleep(20)
print("Status update loop has ended.")
@bot.event
async def on_ready():
await update_status()
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
bot.run(token)