Add Renamer cog for admin-only nickname renaming

This commit is contained in:
2026-10-14 18:58:24 -05:00
parent add5c68a9a
commit b3d1a35939
3 changed files with 121 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
"""Package for Renamer cog."""
import json
from pathlib import Path
from redbot.core.bot import Red
from .renamer import Renamer
with Path(__file__).parent.joinpath("info.json").open() as fp:
__red_end_user_data_statement__ = json.load(fp)["end_user_data_statement"]
async def setup(bot: Red) -> None:
"""Load Renamer cog."""
await bot.add_cog(Renamer(bot))
+22
View File
@@ -0,0 +1,22 @@
{
"name": "Renamer",
"author": [
"Scrapyard Cogworks"
],
"short": "Rename people with admin-only commands.",
"description": "Rename individual users, bulk rename multiple users, or mass rename all users with a specific role. Commands require administrator permissions.",
"install_msg": "Thanks for installing Renamer from Scrapyard Cogworks! Visit us at https://homepage.kingstons-scrapyard.net/",
"requirements": [],
"tags": [
"rename",
"nickname",
"admin"
],
"min_bot_version": "3.5.0",
"min_python_version": [
3,
11,
0
],
"end_user_data_statement": "This cog only changes nicknames; it does not store user data."
}
+83
View File
@@ -0,0 +1,83 @@
import discord
from redbot.core import commands, checks, Config
from redbot.core.bot import Red
class Renamer(commands.Cog):
"""Rename users with admin-only commands."""
def __init__(self, bot: Red):
self.bot = bot
self.config = Config.get_conf(self, identifier=182736451)
self.config.register_guild(allowed_roles=[])
@commands.group()
async def renamer(self, ctx: commands.Context):
"""Rename management commands."""
pass
@renamer.command(name="rename")
@commands.guild_only()
@commands.admin_or_permissions(administrator=True)
async def renamer_rename(self, ctx: commands.Context, member: discord.Member, *, nickname: str | None = None):
"""Rename a member. Leave nickname empty to clear it.
Only admins can use this command.
"""
try:
await member.edit(nick=nickname, reason=f"Renamed by {ctx.author}")
if nickname:
await ctx.send(f"Renamed {member.mention} to `{nickname}`.")
else:
await ctx.send(f"Cleared nickname for {member.mention}.")
except discord.Forbidden:
await ctx.send("I don't have permission to rename that member.")
except discord.HTTPException as e:
await ctx.send(f"Failed to rename member: {e}")
@renamer.command(name="bulkrename")
@commands.guild_only()
@commands.admin_or_permissions(administrator=True)
async def renamer_bulkrename(self, ctx: commands.Context, members: commands.Greedy[discord.Member], *, nickname: str):
"""Rename multiple members to the same nickname.
Only admins can use this command.
"""
if not members:
await ctx.send("You must specify at least one member to rename.")
return
renamed = 0
failed = 0
for member in members:
try:
await member.edit(nick=nickname, reason=f"Bulk renamed by {ctx.author}")
renamed += 1
except discord.Forbidden:
failed += 1
except discord.HTTPException:
failed += 1
await ctx.send(f"Renamed {renamed} member(s) to `{nickname}`. Failed: {failed}")
@renamer.command(name="massrename")
@commands.guild_only()
@commands.admin_or_permissions(administrator=True)
async def renamer_massrename(self, ctx: commands.Context, role: discord.Role, *, nickname: str):
"""Rename all members with a specific role to the same nickname.
Only admins can use this command.
"""
members = role.members
if not members:
await ctx.send("No members have that role.")
return
renamed = 0
failed = 0
for member in members:
try:
await member.edit(nick=nickname, reason=f"Mass renamed by {ctx.author}")
renamed += 1
except discord.Forbidden:
failed += 1
except discord.HTTPException:
failed += 1
await ctx.send(f"Renamed {renamed} member(s) with {role.mention} to `{nickname}`. Failed: {failed}")