0
votes

I am trying to a discord bot remove the role "new". So far, its not working. Can anyone tell me why, and what would be correct?

@client.command(pass_context=True)
async def remove(ctx):
    rid = discord.utils.get(ctx.message.server.roles, name="new")
    await ctx.delete_role(ctx.message.server, rid)
    await ctx.say("hi")

Any ideas?

1

1 Answers

0
votes

You should make sure that you are using the most up to date version of discord.py, which as of writing this post is v1.4.0a. The code you are using here seems to be old. The proper way to delete a role with name "new" is as follows:

@client.command()
async def remove(ctx):
   role = discord.utils.get(ctx.guild.roles, name='new')
   await role.delete(reason='Removed by command')

The full documentation can be found here: https://discordpy.readthedocs.io/en/latest/index.html

The specific method discord.Role.delete can be found here: https://discordpy.readthedocs.io/en/latest/api.html?highlight=discord%20role%20delete#discord.Role.delete

I suggest not following YouTube videos as many of them are outdated.