Files
Syntrel/cogs/moderation/nick.py

67 lines
2.7 KiB
Python
Raw Normal View History

2025-09-14 18:54:56 -04:00
import discord
from discord import app_commands
from discord.ext import commands
def nick_command():
2025-09-14 18:54:56 -04:00
@commands.hybrid_command(
name="nick",
description="Change the nickname of a user on a server.",
)
@app_commands.describe(
user="The user that should have a new nickname.",
nickname="The new nickname that should be set.",
)
2025-11-02 23:32:52 -05:00
async def nick(self, context, user: discord.User, *, nickname: str = None):
2025-09-14 18:54:56 -04:00
"""
Change the nickname of a user on a server.
:param context: The hybrid command context.
: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.
"""
2025-09-15 23:50:07 -04:00
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,
2025-11-02 23:32:52 -05:00
).set_author(
name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png"
)
2025-09-15 23:50:07 -04:00
return await context.send(embed=embed, ephemeral=True)
2025-11-02 23:32:52 -05:00
2025-09-15 23:50:07 -04:00
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,
2025-11-02 23:32:52 -05:00
).set_author(
name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png"
)
2025-09-15 23:50:07 -04:00
return await context.send(embed=embed, ephemeral=True)
2025-09-14 18:54:56 -04:00
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
user.id
)
try:
await member.edit(nick=nickname)
embed = discord.Embed(
2025-09-15 23:50:07 -04:00
title="Nickname",
2025-09-14 18:54:56 -04:00
description=f"**{member}'s** new nickname is **{nickname}**!",
2025-09-15 23:50:07 -04:00
color=0x7289DA,
2025-11-02 23:32:52 -05:00
).set_author(
name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png"
)
2025-09-14 18:54:56 -04:00
await context.send(embed=embed)
except:
embed = discord.Embed(
2025-09-15 23:50:07 -04:00
title="Missing Permissions!",
2025-09-14 18:54:56 -04:00
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,
2025-11-02 23:32:52 -05:00
).set_author(
name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png"
)
2025-09-15 23:50:07 -04:00
await context.send(embed=embed, ephemeral=True)
2025-11-02 23:32:52 -05:00
return nick