Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

reaction role discord.py

@bot.command(pass_context=True)
async def giverole(ctx, user: discord.Member, role: discord.Role):
    await user.add_roles(role)
    await ctx.send(f"hey {ctx.author.name}, {user.name} has been giving a role called: {role.name}")
Comment

reaction role discord.py

roleVer = 'BOT' #role to add
user = ctx.message.author #user
role = roleVer # change the name from roleVer to role

await ctx.send("""Attempting to Verify {}""".format(user))
try:
    await user.add_roles(discord.utils.get(user.guild.roles, name=role)) #add the role
except Exception as e:
    await ctx.send('There was an error running this command ' + str(e)) #if error
else:
    await ctx.send("""Verified: {}""".format(user)) # no errors, say verified
Comment

reaction role discord.py

@role.error
async def role_error(ctx, error):
  if isinstance(error, MissingPermissions):
    await ctx.send('**:x: | You do not have permission to use this command!**')
Comment

reaction role discord.py

@client.command('role')
@commands.has_permissions(administrator=True) #permissions
async def role(ctx, user : discord.Member, *, role : discord.Role):
  if role.position > ctx.author.top_role.position: #if the role is above users top role it sends error
    return await ctx.send('**:x: | That role is above your top role!**') 
  if role in user.roles:
      await user.remove_roles(role) #removes the role if user already has
      await ctx.send(f"Removed {role} from {user.mention}")
  else:
      await user.add_roles(role) #adds role if not already has it
      await ctx.send(f"Added {role} to {user.mention}")
Comment

PREVIOUS NEXT
Code Example
Python :: sqlalchemy function for default value for column 
Python :: python list comprehension with filter 
Python :: extend python 
Python :: pandas filter 
Python :: python floor float 
Python :: child class in python 
Python :: phyton "2.7" print 
Python :: change the format of date in python 
Python :: map vs apply pandas 
Python :: pandas save dataframe with list 
Python :: python calculator 
Python :: rgb to hex python 
Python :: login required 
Python :: How to split a string into a dictionary in Python 
Python :: django pytest how to load data 
Python :: vector data 
Python :: pyautogui 
Python :: python looping through a list 
Python :: python size of set 
Python :: python linkedin api 
Python :: dfs 
Python :: Python RegEx SubString – re.sub() Syntax 
Python :: Python NumPy concatenate Function Syntax 
Python :: python programming language 
Python :: python string 
Python :: how to read a file in python 
Python :: get element by index in list python 
Python :: python enum 
Python :: Adding column to CSV Dictreader 
Python :: dataframe python diplay 2 tables on same line 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =