“Ajout de rôles discordes py” Réponses codées

discord.py comment donner un rôle à un utilisateur

# If ctx is not defined and you are handling a message, use this code
ctx = await bot.get_context(message)

# This is the code needed to give a user a role
member = ctx.message.author # Member object that you want to add the role to
role = discord.utils.get(lambda role: role.name == "Role Name", ctx.guild.roles) # The role object
await member.add_roles(role) # Adds the role to the member
The Angriest Crusader

Ajouter un rôle Discord .py

member = message.author
var = discord.utils.get(message.guild.roles, name = "role name")
member.add_role(var)
Tyrannicodin16

Créer un rôle avec Discord.py

@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')
HelloWorld

Ajout de rôles discordes py

# If you need this in a bot command
@discord.ext.commands.command()
async def online(ctx):
  	guild_id = ctx.guild.id # the guild id where the command has been called
    role = discord.utils.get(bot.get_guild(guild_id).roles, id ="""The Id of the role you search""")
    await member.add_roles(role) # The role gets added to a given Member 
meppi

Ajout de rôles discordes py

# If you need this in a bot command
@bot.command()
async def online(ctx):
    role = discord.utils.get(bot.get_guild(ctx.guild.id).roles, id ="Role ID")
    await member.add_roles(role)
Happy Horse

Ajouter un rôle Discord .py


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)

Wide-eyed Wildebeest

Réponses similaires à “Ajout de rôles discordes py”

Questions similaires à “Ajout de rôles discordes py”

Plus de réponses similaires à “Ajout de rôles discordes py” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code