xxxxxxxxxx
@client.command(aliases=['make_role'])
@commands.has_permissions(manage_roles=True) # Check if the user executing the command can manage roles
async def create_role(ctx, *, name):
guild = ctx.guild
await guild.create_role(name=name)
await ctx.send(f'Role `{name}` has been created')
xxxxxxxxxx
member = message.author
var = discord.utils.get(message.guild.roles, name = "role name")
member.add_role(var)
xxxxxxxxxx
from discord.ext import commands
from discord.utils import get
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
@commands.has_role("Admin") # This must be exactly the name of the appropriate role
async def addrole(ctx):
member = ctx.message.author
role = get(member.server.roles, name="Test")
await bot.add_roles(member, role)
xxxxxxxxxx
@bot.command()
@commands.has_permissions(manage_roles=True)
async def giverole(ctx, member: commands.MemberConverter, Role: discord.Role):
if Role in member.roles:
await ctx.send("**`{0}` already has the `{1}` role!**".format(member.name, Role))
else:
await member.add_roles(Role)
await ctx.send("**Successfully added the role `{0}` to `{1}`**".format(Role, member.name))
xxxxxxxxxx
@client.command(aliases=['make_role'])
@client.command(aliases=['make_role'])
async def create_role(ctx, *, name):
guild = ctx.guild
await guild.create_role(name=name)
await ctx.send(f'Role `{name}` has been created')