feat: nickname permission checks

This commit is contained in:
neoarz
2025-09-15 23:50:07 -04:00
parent 26ad219a26
commit 919ea23a3f

View File

@@ -1,11 +1,3 @@
"""
Copyright © Krypton 2019-Present - https://github.com/kkrypt0nn (https://krypton.ninja)
Description:
🐍 A simple template to start to code your own and personalized Discord bot in Python
Version: 6.4.0
"""
import discord import discord
from discord import app_commands from discord import app_commands
from discord.ext import commands from discord.ext import commands
@@ -20,8 +12,6 @@ class Nick(commands.Cog, name="nick"):
name="nick", name="nick",
description="Change the nickname of a user on a server.", description="Change the nickname of a user on a server.",
) )
@commands.has_permissions(manage_nicknames=True)
@commands.bot_has_permissions(manage_nicknames=True)
@app_commands.describe( @app_commands.describe(
user="The user that should have a new nickname.", user="The user that should have a new nickname.",
nickname="The new nickname that should be set.", nickname="The new nickname that should be set.",
@@ -36,22 +26,40 @@ class Nick(commands.Cog, name="nick"):
:param user: The user that should have its nickname changed. :param user: The user that should have its nickname changed.
:param nickname: The new nickname of the user. Default is None, which will reset the nickname. :param nickname: The new nickname of the user. Default is None, which will reset the nickname.
""" """
if not context.author.guild_permissions.manage_nicknames:
embed = discord.Embed(
title="Missing Permissions!",
description="You are missing the permission(s) `manage_nicknames` to execute this command!",
color=0xE02B2B,
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
return await context.send(embed=embed, ephemeral=True)
if not context.guild.me.guild_permissions.manage_nicknames:
embed = discord.Embed(
title="Missing Permissions!",
description="I am missing the permission(s) `manage_nicknames` to execute this command!",
color=0xE02B2B,
).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
return await context.send(embed=embed, ephemeral=True)
member = context.guild.get_member(user.id) or await context.guild.fetch_member( member = context.guild.get_member(user.id) or await context.guild.fetch_member(
user.id user.id
) )
try: try:
await member.edit(nick=nickname) await member.edit(nick=nickname)
embed = discord.Embed( embed = discord.Embed(
title="Nickname",
description=f"**{member}'s** new nickname is **{nickname}**!", description=f"**{member}'s** new nickname is **{nickname}**!",
color=0xBEBEFE, color=0x7289DA,
) ).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
await context.send(embed=embed) await context.send(embed=embed)
except: except:
embed = discord.Embed( embed = discord.Embed(
title="Missing Permissions!",
description="An error occurred while trying to change the nickname of the user. Make sure my role is above the role of the user you want to change the nickname.", description="An error occurred while trying to change the nickname of the user. Make sure my role is above the role of the user you want to change the nickname.",
color=0xE02B2B, color=0xE02B2B,
) ).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/8VLDcg.webp")
await context.send(embed=embed) await context.send(embed=embed, ephemeral=True)
async def setup(bot) -> None: async def setup(bot) -> None: