Discord.py how to delete all roles in server
Question:
I’m trying to delete all roles in my discord server, but it takes a huge amount of time. So I decided to do this task with discord.py
bot, but I’m getting this error:
discord.errors.HTTPException: 400 Bad Request (error code: 50028): Invalid Role
Here’s my code:
@client.command()
async def delroles(ctx):
for role in ctx.guild.roles:
await role.delete()
Answers:
The problem is that all users have an "invisible role" called @everyone
, which is impossible to remove.
Do:
async def delroles(ctx):
for role in ctx.guild.roles:
try:
await role.delete()
except:
await ctx.send(f"Cannot delete {role.name}")
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='>')
@client.event
async def on_ready():
print("Log : "+str(client.user))
@client.command()
async def delete(ctx):
for role in ctx.guild.roles:
try:
await role.delete()
except:
pass
client.run("token")
I’m trying to delete all roles in my discord server, but it takes a huge amount of time. So I decided to do this task with discord.py
bot, but I’m getting this error:
discord.errors.HTTPException: 400 Bad Request (error code: 50028): Invalid Role
Here’s my code:
@client.command()
async def delroles(ctx):
for role in ctx.guild.roles:
await role.delete()
The problem is that all users have an "invisible role" called @everyone
, which is impossible to remove.
Do:
async def delroles(ctx):
for role in ctx.guild.roles:
try:
await role.delete()
except:
await ctx.send(f"Cannot delete {role.name}")
import discord
from discord.ext import commands
client = commands.Bot(command_prefix='>')
@client.event
async def on_ready():
print("Log : "+str(client.user))
@client.command()
async def delete(ctx):
for role in ctx.guild.roles:
try:
await role.delete()
except:
pass
client.run("token")