mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 11:40:12 +01:00
style: new code layout
This commit is contained in:
58
cogs/moderation/nick.py
Normal file
58
cogs/moderation/nick.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
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
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
|
||||
class Nick(commands.Cog, name="nick"):
|
||||
def __init__(self, bot) -> None:
|
||||
self.bot = bot
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="nick",
|
||||
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(
|
||||
user="The user that should have a new nickname.",
|
||||
nickname="The new nickname that should be set.",
|
||||
)
|
||||
async def nick(
|
||||
self, context: Context, user: discord.User, *, nickname: str = None
|
||||
) -> None:
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
member = context.guild.get_member(user.id) or await context.guild.fetch_member(
|
||||
user.id
|
||||
)
|
||||
try:
|
||||
await member.edit(nick=nickname)
|
||||
embed = discord.Embed(
|
||||
description=f"**{member}'s** new nickname is **{nickname}**!",
|
||||
color=0xBEBEFE,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
except:
|
||||
embed = discord.Embed(
|
||||
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,
|
||||
)
|
||||
await context.send(embed=embed)
|
||||
|
||||
|
||||
async def setup(bot) -> None:
|
||||
await bot.add_cog(Nick(bot))
|
||||
Reference in New Issue
Block a user