|
1 | 1 | import nextcord |
2 | 2 | import nextcord.errors |
3 | | -from nextcord.ext import commands, tasks |
| 3 | +from nextcord.ext import commands, application_checks |
4 | 4 | import os |
5 | | -from itertools import cycle |
6 | 5 | import sys |
7 | 6 | import configparser |
8 | 7 |
|
|
11 | 10 |
|
12 | 11 | config = configparser.ConfigParser() |
13 | 12 | config.read("config.ini") |
14 | | - |
15 | | -if sys.version_info < (3, 8): |
16 | | - exit("You need Python 3.8+ to run the bot.") |
17 | | - |
18 | | -try: |
19 | | - from nextcord import Intents, Client |
20 | | - |
21 | | -except ImportError: |
22 | | - exit("Nextcord isn`t installed or it`s old, unsupported version.") |
| 13 | +admin_guild = int(config['settings']['admin_guild']) |
23 | 14 |
|
24 | 15 | client = commands.Bot(command_prefix=config["bot"]["prefix"], owner_id=int(config["bot"]["owner_id"]), intents=intents) |
25 | 16 | client.remove_command('help') |
26 | 17 |
|
| 18 | + |
27 | 19 | @client.event |
28 | 20 | async def on_ready(): |
29 | 21 | await client.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.watching, name="bot status")) |
30 | 22 | print("Logged in as {0.user}.".format(client)) |
31 | 23 | print("Bot is using on {0} servers!".format(len(client.guilds))) |
32 | 24 |
|
33 | | -# загрузка когов |
| 25 | + |
| 26 | +@client.event |
| 27 | +async def on_disconnect(): |
| 28 | + if client.is_closed(): |
| 29 | + await client.connect() |
| 30 | + |
| 31 | + |
| 32 | +# WORKING WITH COGS |
34 | 33 |
|
35 | 34 |
|
36 | | -@client.command() |
37 | | -@commands.is_owner() |
38 | | -async def load(ctx, extension): |
| 35 | +@application_checks.is_owner() |
| 36 | +@client.slash_command(guild_ids=(admin_guild,)) |
| 37 | +async def load(interaction, extension): |
| 38 | + """ |
| 39 | + Loading extension |
| 40 | +
|
| 41 | + Parameters |
| 42 | + ---------- |
| 43 | + interaction: Interaction |
| 44 | + extension: str |
| 45 | + Type name of extension to load. |
| 46 | + """ |
39 | 47 | try: |
40 | 48 | client.load_extension(f"cogs.{extension}") |
41 | 49 | print(f"Cog {extension} is loaded.") |
42 | | - await ctx.send(f"Cog **{str.upper(extension)}** is loaded.") |
| 50 | + await interaction.send(f"Cog **{str.upper(extension)}** is loaded.") |
43 | 51 |
|
44 | 52 | except Exception as error: |
45 | 53 | print(error) |
46 | | - await ctx.send("Incorrect name or not able to load") |
| 54 | + await interaction.send("Incorrect name or not able to load") |
| 55 | + |
47 | 56 |
|
| 57 | +@application_checks.is_owner() |
| 58 | +@client.slash_command(guild_ids=(admin_guild,)) |
| 59 | +async def unload(interaction, extension): |
| 60 | + """ |
| 61 | + Unloading extension |
48 | 62 |
|
49 | | -@client.command() |
50 | | -@commands.is_owner() |
51 | | -async def unload(ctx, extension): |
| 63 | + Parameters |
| 64 | + ---------- |
| 65 | + interaction: Interaction |
| 66 | + extension: str |
| 67 | + Type name of extension to unload. |
| 68 | + """ |
52 | 69 | try: |
53 | 70 | client.unload_extension(f"cogs.{extension}") |
54 | 71 | print(f"Cog {str.upper(extension)} is unloaded.") |
55 | | - await ctx.send(f"Cog **{str.upper(extension)}** is unloaded.") |
| 72 | + await interaction.send(f"Cog **{str.upper(extension)}** is unloaded.") |
56 | 73 |
|
57 | 74 | except Exception as error: |
58 | 75 | print(error) |
59 | | - await ctx.send("Incorrect name or not able to unload") |
| 76 | + await interaction.send("Incorrect name or not able to unload") |
60 | 77 |
|
61 | 78 |
|
62 | | -@client.command() |
63 | | -@commands.is_owner() |
64 | | -async def reload(ctx, extension): |
| 79 | +@application_checks.is_owner() |
| 80 | +@client.slash_command(guild_ids=(admin_guild,)) |
| 81 | +async def reload(interaction, extension): |
| 82 | + """ |
| 83 | + Reloading extension |
| 84 | +
|
| 85 | + Parameters |
| 86 | + ---------- |
| 87 | + interaction: Interaction |
| 88 | + extension: str |
| 89 | + Type name of extension to reload. |
| 90 | + """ |
65 | 91 | try: |
66 | 92 | client.unload_extension(f"cogs.{extension}") |
67 | 93 | client.load_extension(f"cogs.{extension}") |
68 | 94 | print(f"Cog {str.upper(extension)} is reloaded.") |
69 | | - await ctx.send(f"Cog **{str.upper(extension)}** is reloaded.") |
| 95 | + await interaction.send(f"Cog **{str.upper(extension)}** is reloaded.") |
70 | 96 |
|
71 | 97 | except Exception as error: |
72 | 98 | print(error) |
73 | | - await ctx.send("Incorrect name or not able to reload") |
| 99 | + await interaction.send("Incorrect name or not able to reload") |
74 | 100 |
|
75 | 101 | for filename in os.listdir("./cogs"): |
76 | 102 | if filename.endswith(".py"): |
77 | 103 | client.load_extension(f"cogs.{filename[:-3]}") |
78 | 104 |
|
79 | | -try: |
80 | | - client.run(config["bot"]["token"]) |
| 105 | +if __name__ == '__main__': |
| 106 | + if sys.version_info < (3, 8): |
| 107 | + exit("You need Python 3.8+ to run the bot.") |
| 108 | + |
| 109 | + try: |
| 110 | + from nextcord import Intents, Client |
| 111 | + |
| 112 | + except ImportError: |
| 113 | + exit("Nextcord isn`t installed or it`s old, unsupported version.") |
| 114 | + |
| 115 | + try: |
| 116 | + client.run(config["bot"]["token"]) |
81 | 117 |
|
82 | | -except Exception as err: |
83 | | - print(err) |
| 118 | + except Exception as err: |
| 119 | + print(err) |
84 | 120 |
|
85 | | -except nextcord.PrivilegedIntentsRequired: |
86 | | - exit("Login failure! Privileged Intents not enabled.") |
| 121 | + except nextcord.PrivilegedIntentsRequired: |
| 122 | + exit("Login failure! Privileged Intents not enabled.") |
87 | 123 |
|
88 | | -except nextcord.errors.LoginFailure: |
89 | | - exit("Login failure! Token is required.") |
| 124 | + except nextcord.errors.LoginFailure: |
| 125 | + exit("Login failure! Token is required.") |
0 commit comments