I'm trying to get this to check if the user has the role that's tagged or not.
discord.utils.get(ctx.guild.roles, name=rolename) and discord.utils.get(user.roles, name=rolename)
@bot.command()
@commands.has_permissions(manage_roles=True)
async def giverole(ctx, user: discord.Member, rolename: discord.Role):
role = discord.utils.get(ctx.guild.roles, name=rolename)
if(not role in user.roles):
await user.add_roles(rolename)
embed=discord.Embed(title=f"{user.name} Has been added to a role called: {rolename.name}", color=discord.Color.dark_purple())
await ctx.send(embed=embed)
else:
await ctx.send(f"Hey {ctx.author.name}, {user.name} already has the role called: {rolename.name}")
No errors just keeps giving the role instead of checking if the user has the role or not.
@bot.command()
@commands.has_permissions(manage_roles=True)
async def giverole(ctx, user: discord.Member=None, rolename:discord.Role=None):
if rolename in user.roles:
await ctx.send("Person already has role")
else:
await user.add_roles(rolename)
await ctx.send("Person doesn't have the role and it has been given to him/her")
Make sure the bot's role is higher than the role you're trying to give the user though because if It's not then you'll get error 50013 Missing Permissions.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments