Skip to content

Commit 794c9c3

Browse files
authored
Merge pull request #18 from r-liner/develop
v0.8-rc.1
2 parents 974defe + 65e761f commit 794c9c3

11 files changed

+383
-258
lines changed

cogs/admin.py

+55-42
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,82 @@
11
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"]
38

49

510
class Admin(commands.Cog):
611
def __init__(self, client):
712
self.client = client
813

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+
"""
3743
try:
3844
await user.send(message)
39-
await ctx.send("Message has sent")
45+
await interaction.send("Message has sent")
4046

4147
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+
"""
4756
print("Bot is shutting down")
48-
await ctx.send("Bot is shutting down")
57+
await interaction.send("Bot is shutting down")
4958
await self.client.close()
5059

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+
"""
5466
try:
5567
embed = nextcord.Embed(description=content)
5668
embed.add_field(name="Result", value=eval(content))
57-
await ctx.send(embed=embed)
69+
await interaction.send(embed=embed)
5870

5971
except SyntaxError:
60-
await ctx.send("Incorrect expression")
72+
await interaction.send("Incorrect expression")
6173

6274
except ZeroDivisionError:
63-
await ctx.send("Cannot be divided by zero!")
75+
await interaction.send("Cannot be divided by zero!")
6476

6577
except Exception as error:
6678
print(error)
79+
await interaction.send(f"Error message:\n```{error}```")
6780

6881

6982
def setup(client):

cogs/discord.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import nextcord
2-
from nextcord.ext import commands
2+
from nextcord.ext import commands, application_checks
33

44

55
class Discord(commands.Cog):
66
def __init__(self, client):
77
self.client = client
88

9-
# Avatar
10-
@commands.command()
11-
@commands.guild_only()
12-
async def avatar(self, ctx, *, user: nextcord.Member = None):
13-
user = user or ctx.author
14-
try:
15-
if user.avatar or user.guild_avatar:
16-
user_avatar = user.avatar.url
17-
embed = nextcord.Embed(title=f"Avatar of user **{user.name}**")
18-
embed.set_image(url=user_avatar)
19-
await ctx.send(embed=embed)
9+
@application_checks.guild_only()
10+
@nextcord.slash_command()
11+
async def avatar(self, interaction, user: nextcord.Member = nextcord.SlashOption(default=None)):
12+
user = user or interaction.user
2013

21-
elif not user.avatar and not user.guild_avatar:
22-
return await ctx.send("User has no avatar.")
14+
if user.avatar or user.guild_avatar:
15+
user_avatar = user.avatar.url
16+
embed = nextcord.Embed(title=f"Avatar of user **{user.name}**")
17+
embed.set_image(url=user_avatar)
18+
await interaction.send(embed=embed)
2319

24-
except Exception as err:
25-
print(err)
20+
elif not user.avatar and not user.guild_avatar:
21+
return await interaction.send("User has no avatar.")
2622

2723

2824
def setup(client):

cogs/events.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import nextcord
2-
from nextcord.ext import commands
2+
from nextcord.ext import commands, application_checks
33
from nextcord.ext.commands import errors
44

55

@@ -20,6 +20,23 @@ async def on_command_error(self, ctx, err: Exception):
2020
elif isinstance(err, errors.MissingPermissions):
2121
await ctx.send("You haven`t permissions.")
2222

23+
@commands.Cog.listener()
24+
async def on_application_command_error(self, interaction, error: Exception):
25+
embed = nextcord.Embed(title="Error", colour=nextcord.Colors.light_red)
26+
27+
if isinstance(error, application_checks.errors.ApplicationMissingPermissions):
28+
embed.description = "You do not have permissions to perform this action."
29+
embed.add_field(name="Hint", value="Permissions needed, for example: \"BAN MEMBERS\".")
30+
31+
if isinstance(error, nextcord.errors.ApplicationInvokeError):
32+
embed.description = "Bot does not have sufficient permissions."
33+
embed.add_field(name="Hint", value="Give the bot administrator permissions and make its role higher than others (except admins).")
34+
embed.add_field(name="Hint 2", value="The error could be on the developer's side. Please report this to the developer.")
35+
36+
if isinstance(error, application_checks.errors.ApplicationNSFWChannelRequired):
37+
embed.description = "Channel is not NSFW."
38+
embed.add_field(name="Hint", value="Send the command in an NSFW channel.")
39+
2340
@commands.Cog.listener()
2441
async def on_message(self, message):
2542
print("{0.guild} - {0.author}: {0.content}".format(message))

0 commit comments

Comments
 (0)