This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
152 lines (117 loc) · 3.84 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import nextcord
import nextcord.errors
from nextcord.ext import commands, application_checks
import os
import sys
import configparser
from cogs.utils import dependecies, github, version
intents = nextcord.Intents.all()
config = configparser.ConfigParser()
config.read("config.ini")
admin_guild = int(config['settings']['admin_guild'])
client = commands.Bot(command_prefix=config["bot"]["prefix"], owner_id=int(config["bot"]["owner_id"]), intents=intents)
client.remove_command('help')
dependecies.check_installed()
if github.check_for_updates(version.get()):
latest = github.get_latest()
print(f"[GITHUB]: New update available: v{latest}")
print(f"CHANGELOG:\n-----------\n{github.changelog()}-----------")
@client.event
async def on_ready():
await client.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.watching, name="bot status"))
print("Logged in as {0.user}.".format(client))
print("Bot is using on {0} servers!".format(len(client.guilds)))
@client.event
async def on_disconnect():
if client.is_closed():
await client.connect()
# WORKING WITH COGS
@client.slash_command(guild_ids=(admin_guild,))
async def cogs(interaction):
pass
@application_checks.is_owner()
@cogs.subcommand()
async def load(interaction, extension):
"""
Loading extension.
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to load.
"""
try:
client.load_extension(f"cogs.{extension}")
print(f"Cog {extension} is loaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is loaded.")
except Exception as error:
print(error)
await interaction.send("Incorrect name or not able to load")
@application_checks.is_owner()
@cogs.subcommand()
async def unload(interaction, extension):
"""
Unloading extension.
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to unload.
"""
try:
client.unload_extension(f"cogs.{extension}")
print(f"Cog {str.upper(extension)} is unloaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is unloaded.")
except Exception as error:
print(error)
await interaction.send("Incorrect name or not able to unload")
@application_checks.is_owner()
@cogs.subcommand()
async def reload(interaction, extension):
"""
Reloading extension.
Parameters
----------
interaction: Interaction
extension: str
Type name of extension to reload.
"""
try:
client.unload_extension(f"cogs.{extension}")
client.load_extension(f"cogs.{extension}")
print(f"Cog {str.upper(extension)} is reloaded.")
await interaction.send(f"Cog **{str.upper(extension)}** is reloaded.")
except Exception as error:
print(error)
await interaction.send("Incorrect name or not able to reload")
@application_checks.is_owner()
@cogs.subcommand()
async def list(interaction):
"""
Get extensions list.
"""
embed = nextcord.Embed(title="Cogs list", color=nextcord.Color.blue())
description = []
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
description.append(f"- {filename[:-3]}")
embed.description = "\n".join(description)
await interaction.send(embed=embed)
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")
if __name__ == '__main__':
if sys.version_info < (3, 8):
exit("You need Python 3.8+ to run the bot.")
try:
from nextcord import Intents, Client
except ImportError:
exit("Nextcord isn`t installed or it`s old, unsupported version.")
try:
client.run(config["bot"]["token"])
except nextcord.PrivilegedIntentsRequired:
exit("Login failure! Privileged Intents not enabled.")
except nextcord.errors.LoginFailure:
exit("Login failure! Token is required.")
except Exception as err:
print(err)