-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.py
More file actions
103 lines (82 loc) · 2.86 KB
/
Bot.py
File metadata and controls
103 lines (82 loc) · 2.86 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import asyncio,random,time
import discord#discord.py==1.3.3
from discord.ext import commands
import socket,math
import FileRW
#########################################################global variable define
polls=[]#polls data
isBuilding = False
#########################################################read confing
config = FileRW.readConfig('DiscordBotConfig.ini')
emoji = FileRW.readEmoji()
#########################################################bot init
intents = discord.Intents.all()
bot = commands.Bot(command_prefix = config['prefix'])
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.command()
async def load(ctx, ExtensionName):
try:
bot.load_extension(f"Commands.{ExtensionName}")
await ctx.send(f"{ExtensionName} has loaded")
except:
await ctx.send(f"{ExtensionName} not found")
@bot.command()
async def loadAll(ctx):
categorys = FileRW.readCategory('Commands_Category.json')
success_categorys = []
failed_categorys = []
for category in categorys:
try:
bot.load_extension(f"Commands.{category}")
success_categorys.append(category)
except:
failed_categorys.append(category)
if(len(success_categorys)>0):
categorys_string = " , ".join(success_categorys)
await ctx.send(f"{categorys_string} has loaded")
if(len(failed_categorys)>0):
categorys_string = " , ".join(failed_categorys)
await ctx.send(f"{categorys_string} has failed")
@bot.command()
async def unload(ctx, ExtensionName):
try:
r=bot.unload_extension(f"Commands.{ExtensionName}")
await ctx.send(f"{ExtensionName} has removed")
except:
await ctx.send(f"{ExtensionName} not found")
@bot.command()
async def reload(ctx, ExtensionName):
try:
bot.reload_extension(f"Commands.{ExtensionName}")
await ctx.send(f"{ExtensionName} has reloaded")
except:
await ctx.send(f"{ExtensionName} not found")
@bot.command()
async def status(ctx):
global bootDate
def sec2str(time):
day = math.floor( time/(60*60*24) )
time = time - (60*60*24)*day
hour = math.floor( time/(60*60) )
time = time - (60*60)*hour
min = math.floor( time/(60) )
time = time - (60)*min
sec = math.floor(time)
return(f"{day}days {hour}:{min}:{sec}")
hostname = socket.gethostname()
Time=sec2str(time.time() - bootDate)
latency=int(bot.latency*1000)
msg=f"""```
Running on: {hostname}
Online Time: {Time}
Latency: {latency}ms
```"""
await ctx.send(msg)
#for file in os.listdir("./Commands"):
# if(file.endswith(".py")):
# bot.load_extension(f"Commands.{file[:-3]}")
bootDate = time.time()
bot.run(config['Token'])