“Commande d'interdiction dans Discord.py” Réponses codées

Discord.py Ban

@commands.command() # uses command decorators, in this case inside a cog
@commands.has_permissions(ban_members=True) # only people that have permissions to ban users can use this command
async def ban(self, ctx, user: discord.Member, *, reason): # The person banning someone has to ping the user to ban, and input a reason. Remove self if you are outside a cog.
    await ctx.guild.ban(user, reason=reason) # Bans the user.
    await user.send(f"You have been banned in {ctx.guild} for {reason}") # Private messages user.
    await ctx.send(f"{user} has been successfully banned.") # messages channel to tell everyone it worked
Oblique

Commande d'interdiction dans Discord.py

#this is what you want!
@bot.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, user: discord.Member, *, reason=None):
	if reason == None:
		reason = f"{user} banned by {ctx.author}"
	if ctx.author.top_role < user.top_role:
		return await ctx.send("**You don't have enough permission**')
	if ctx.author.top_role > user.top_role:
		return await ctx.guild.ban(user, reason=reason)
		return await ctx.send(f"{user} Successfully Banned by {ctx.author.mention}")
Hunter 87

Réponses similaires à “Commande d'interdiction dans Discord.py”

Questions similaires à “Commande d'interdiction dans Discord.py”

Plus de réponses similaires à “Commande d'interdiction dans Discord.py” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code