Saltar al contenido

ejecutar comandos solo si el usuario tiene permisos de administrador ejemplo de código discord.py

Nuestro equipo de trabajo ha pasado mucho tiempo investigando la solución a tus preguntas, te regalamos la soluciones y nuestro objetivo es resultarte de mucha apoyo.

Ejemplo 1: permisos de comando del bot de discordia de Python

@commands.guild_only()# Command cannot be used in private messages.@commands.is_owner()# Command can only be used by the bot owner.@commands.is_nsfw()# Command can only be used in NSFW channels@commands.has_role("name")# Check if member has a role with the name "name"@commands.bot_has_role(11132312313213)# As above, but for the bot itself. (name can be replaced with id)@commands.has_any_role(["role1","foo",11132312313213])# Check if user has any of the roles with the names "role1", "foo", or the role with id 11132312313213@commands.bot_has_any_role(*roles)# As above, but for the bot itself@commands.has_permissions([ban_members=True, kick_members=True])# Check if user has all of the passed permissions #  e.g. this command will require both kick and ban permissions@commands.bot_has_permissions(**perms)# As above, but for the bot itself.@commands.has_guild_permissions(**perms)@commands.bot_has_guild_permissions(**perms)# As for the two above, but for guild permissions rather than channel permissions.@commands.check(myfunction)# Check against your own function that returns those able to use your command@commands.check_any(*myfunctions)# Command will be ran if the conditions of any of your own check functions are metfrom discord.ext.commands.cooldowns import BucketType
# BucketType can be BucketType.default, member, user, guild, role, or channel@commands.cooldown(rate,per,BucketType)# Limit how often a command can be used, (num per, seconds, BucketType)@commands.max_concurrency(number, per=BucketType.default,*, wait=False)# Limit how many instances of the command can be running at the same time.# Setting wait=True will queue up additional commands. False will raise MaxConcurrencyReached# Checks can be stacked, and will Raise a CheckFailure if any check fails.

Ejemplo 2: discord.py cómo usar los permisos

from discord import Member
from discord.ext.commands import has_permissions, MissingPermissions

@bot.command(name="kick", pass_context=True)@has_permissions(manage_roles=True, ban_members=True)asyncdef_kick(ctx, member: Member):await bot.kick(member)@_kick.errorasyncdefkick_error(error, ctx):ifisinstance(error, MissingPermissions):
        text ="Sorry , you do not have permissions to do that!".format(ctx.message.author)await bot.send_message(ctx.message.channel, text)

Sección de Reseñas y Valoraciones

Recuerda que puedes difundir esta división si te valió la pena.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *