|
1 | 1 | import nextcord
|
2 |
| -from nextcord.ext import commands |
| 2 | +from nextcord.ext import commands, application_checks |
| 3 | +import configparser |
| 4 | + |
| 5 | +config = configparser.ConfigParser() |
| 6 | +config.read("config.ini") |
| 7 | +admin_guilds = config["settings"]["admin_guild"] |
3 | 8 |
|
4 | 9 |
|
5 | 10 | class Admin(commands.Cog):
|
6 | 11 | def __init__(self, client):
|
7 | 12 | self.client = client
|
8 | 13 |
|
9 |
| - @commands.command(aliases=["cn"]) |
10 |
| - @commands.is_owner() |
11 |
| - async def change_nickname(self, ctx, *, name: str = None): |
12 |
| - try: |
13 |
| - await ctx.guild.me.edit(nick=name) |
14 |
| - |
15 |
| - if name: |
16 |
| - return await ctx.send(f"Display name of bot has changed on **{name}**") |
17 |
| - |
18 |
| - elif name is None: |
19 |
| - return await ctx.send(f"Nickname has cleared") |
20 |
| - |
21 |
| - except Exception as error: |
22 |
| - await ctx.send(error) |
23 |
| - |
24 |
| - @commands.command(aliases=["cu"]) |
25 |
| - @commands.is_owner() |
26 |
| - async def change_username(self, ctx, *, name: str): |
27 |
| - try: |
28 |
| - await self.client.user.edit(username=name) |
29 |
| - await ctx.send(f"Username of bot has changed on **{name}**") |
30 |
| - |
31 |
| - except Exception as error: |
32 |
| - await ctx.send(error) |
33 |
| - |
34 |
| - @commands.command(aliases=["dm"]) |
35 |
| - @commands.is_owner() |
36 |
| - async def direct_message(self, ctx, user: nextcord.User, *, message: str): |
| 14 | + @application_checks.is_owner() |
| 15 | + @nextcord.slash_command() |
| 16 | + async def change_nickname(self, interaction, name: str = nextcord.SlashOption(default=None)): |
| 17 | + """ |
| 18 | + [ADMIN] Change bot nickname. |
| 19 | + """ |
| 20 | + await interaction.guild.me.edit(nick=name) |
| 21 | + |
| 22 | + if name: |
| 23 | + return await interaction.send(f"Display name of bot has changed on **{name}**") |
| 24 | + |
| 25 | + elif name is None: |
| 26 | + return await interaction.send(f"Nickname has cleared") |
| 27 | + |
| 28 | + @application_checks.is_owner() |
| 29 | + @nextcord.slash_command(guild_ids=(admin_guilds,)) |
| 30 | + async def change_username(self, interaction, name: str = nextcord.SlashOption(default=None)): |
| 31 | + """ |
| 32 | + [ADMIN] Change bot username. |
| 33 | + """ |
| 34 | + await self.client.user.edit(username=name) |
| 35 | + await interaction.send(f"Username of bot has changed on **{name}**") |
| 36 | + |
| 37 | + @application_checks.is_owner() |
| 38 | + @nextcord.slash_command() |
| 39 | + async def direct_message(self, interaction, user: nextcord.User, message: str): |
| 40 | + """ |
| 41 | + [ADMIN] Send direct message to selected user. |
| 42 | + """ |
37 | 43 | try:
|
38 | 44 | await user.send(message)
|
39 |
| - await ctx.send("Message has sent") |
| 45 | + await interaction.send("Message has sent") |
40 | 46 |
|
41 | 47 | except nextcord.Forbidden:
|
42 |
| - await ctx.send("User`s dm unreacheable.") |
43 |
| - |
44 |
| - @commands.command(aliases=["shut"], pass_context=True) |
45 |
| - @commands.is_owner() |
46 |
| - async def shutdown(self, ctx): |
| 48 | + await interaction.send("User`s dm unreacheable.") |
| 49 | + |
| 50 | + @application_checks.is_owner() |
| 51 | + @nextcord.slash_command(guild_ids=(admin_guilds,)) |
| 52 | + async def shutdown(self, interaction): |
| 53 | + """ |
| 54 | + [ADMIN] Turns off the bot. |
| 55 | + """ |
47 | 56 | print("Bot is shutting down")
|
48 |
| - await ctx.send("Bot is shutting down") |
| 57 | + await interaction.send("Bot is shutting down") |
49 | 58 | await self.client.close()
|
50 | 59 |
|
51 |
| - @commands.is_owner() |
52 |
| - @commands.command() |
53 |
| - async def eval(self, ctx, *, content): |
| 60 | + @application_checks.is_owner() |
| 61 | + @nextcord.slash_command(guild_ids=(admin_guilds,)) |
| 62 | + async def eval(self, interaction, content): |
| 63 | + """ |
| 64 | + [ADMIN] Evaluates a Python expression. |
| 65 | + """ |
54 | 66 | try:
|
55 | 67 | embed = nextcord.Embed(description=content)
|
56 | 68 | embed.add_field(name="Result", value=eval(content))
|
57 |
| - await ctx.send(embed=embed) |
| 69 | + await interaction.send(embed=embed) |
58 | 70 |
|
59 | 71 | except SyntaxError:
|
60 |
| - await ctx.send("Incorrect expression") |
| 72 | + await interaction.send("Incorrect expression") |
61 | 73 |
|
62 | 74 | except ZeroDivisionError:
|
63 |
| - await ctx.send("Cannot be divided by zero!") |
| 75 | + await interaction.send("Cannot be divided by zero!") |
64 | 76 |
|
65 | 77 | except Exception as error:
|
66 | 78 | print(error)
|
| 79 | + await interaction.send(f"Error message:\n```{error}```") |
67 | 80 |
|
68 | 81 |
|
69 | 82 | def setup(client):
|
|
0 commit comments