rank
Private
Content
49 linesimport discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
bot = commands.Bot(command_prefix=':!', intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
print('Ready to test role swapping!')
@bot.command(name='role')
@commands.has_permissions(manage_roles=True)
async def swap_role(ctx, member: discord.Member, new_role: discord.Role):
# Prevent running the command on the server owner
if member.id == ctx.guild.owner_id:
return await ctx.send("❌ Discord API rules prevent bots from altering the Server Owner's roles!")
try:
# 1. Fetch fresh data directly from Discord
fresh_member = await ctx.guild.fetch_member(member.id)
# 2. Find every role that can safely be removed
roles_to_remove = [
role for role in fresh_member.roles
if not role.is_default() and not role.managed and role.id != new_role.id
]
# 3. Explicitly loop and remove each role
if roles_to_remove:
for role in roles_to_remove:
print(f"Attempting to remove role: {role.name}")
await fresh_member.remove_roles(role)
# 4. Add the brand new role
print(f"Attempting to add role: {new_role.name}")
await fresh_member.add_roles(new_role)
await ctx.send(f'✅ Wiped {len(roles_to_remove)} old roles and assigned **{new_role.name}** to **{fresh_member.display_name}**!')
except discord.Forbidden:
await ctx.send("❌ **Discord Hierarchy Error:** The bot role is too low! Drag the bot role to the very top of `Server Settings > Roles`.")
except discord.HTTPException as e:
await ctx.send(f"❌ Network Error: {e}")
bot.run('YOUR_BOT_TOKEN_HERE')Raw JSON
{
"id": 2743819,
"created_at": "2026-08-26T04:37:53.000Z",
"tag_name": "rank",
"nsfw": false,
"owner_id": "1535464744914391091",
"uses": 0,
"description": null,
"restricted": false,
"shared": false,
"deleted": false,
"safe": "",
"hidden": false,
"guild_id": "1541997682682499183",
"sharer": "1535464744914391091",
"content": "import discord\nfrom discord.ext import commands\n\nintents = discord.Intents.default()\nintents.message_content = True \nintents.members = True \n\nbot = commands.Bot(command_prefix=':!', intents=intents)\n\n@bot.event\nasync def on_ready():\n print(f'Logged in as {bot.user.name}')\n print('Ready to test role swapping!')\n\n@bot.command(name='role')\n@commands.has_permissions(manage_roles=True) \nasync def swap_role(ctx, member: discord.Member, new_role: discord.Role):\n # Prevent running the command on the server owner\n if member.id == ctx.guild.owner_id:\n return await ctx.send(\"❌ Discord API rules prevent bots from altering the Server Owner's roles!\")\n\n try:\n # 1. Fetch fresh data directly from Discord\n fresh_member = await ctx.guild.fetch_member(member.id)\n \n # 2. Find every role that can safely be removed\n roles_to_remove = [\n role for role in fresh_member.roles \n if not role.is_default() and not role.managed and role.id != new_role.id\n ]\n \n # 3. Explicitly loop and remove each role\n if roles_to_remove:\n for role in roles_to_remove:\n print(f\"Attempting to remove role: {role.name}\")\n await fresh_member.remove_roles(role)\n \n # 4. Add the brand new role\n print(f\"Attempting to add role: {new_role.name}\")\n await fresh_member.add_roles(new_role)\n \n await ctx.send(f'✅ Wiped {len(roles_to_remove)} old roles and assigned **{new_role.name}** to **{fresh_member.display_name}**!')\n \n except discord.Forbidden:\n await ctx.send(\"❌ **Discord Hierarchy Error:** The bot role is too low! Drag the bot role to the very top of `Server Settings > Roles`.\")\n except discord.HTTPException as e:\n await ctx.send(f\"❌ Network Error: {e}\")\n\nbot.run('YOUR_BOT_TOKEN_HERE')",
"embed": "{}",
"last_fetched": "2026-10-25T07:32:00.158Z"
}