Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

ban discord.py

@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member: discord.Member, *, reason=None):
    await member.ban(reason=reason)
    await ctx.send(f'User {member} has been baned from the server.')
Comment

ban command in 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}")
Comment

discord.py ban

#Replace "nextcord" with "discord" if you use discord.py!
#If something doesnt work message me @ Discord: VeryAppropriateName#0195

@bot.command()
@commands.cooldown(1, 3, commands.BucketType.user)
@has_permissions(administrator=True)
async def ban(ctx, member: nextcord.Member = None, *, reason="No reason provided"):
    if member is None:
        embed = nextcord.Embed(title="Command: !ban",
                               description=f"**Description:** Ban a member, optional reason
**Cooldown:** 3 Seconds",
                               color=0x2596be)
        embed.add_field(name="Usage:", value=f"!ban [user] [reason]", inline=False)
        embed.add_field(name="Example:", value=f"!ban bean squishing bugs", inline=False)
        await ctx.send(embed=embed)
    else:
        embed = nextcord.Embed(title="You got banned!",
                               description=f"You got banned from {ctx.guild.name}, for {reason}! Better behave next time!",
                               color=0x2596be)
        embed.set_image(url="https://i.gifer.com/41zO.gif")
        await member.send(embed=embed)
        embed = nextcord.Embed(title="", description=f"Banned {member.mention} for {reason}", color=0x2596be)
        embed.set_image(url="https://i.gifer.com/41zO.gif")
        await ctx.send(embed=embed)
        await member.ban(reason=reason)


@bot.command()
@commands.cooldown(1, 3, commands.BucketType.user)
@has_permissions(administrator=True)
async def kick(ctx, member: nextcord.Member = None, *, reason="No reason provided"):
    if member is None:
        embed = nextcord.Embed(title="Command: !kick",
                               description=f"**Description:** Kick a member, optional reason
**Cooldown:** 3 Seconds",
                               color=0x2596be)
        embed.add_field(name="Usage:", value=f"!kick [user] [reason]", inline=False)
        embed.add_field(name="Example:", value=f"!kick bean squishing bugs", inline=False)
        await ctx.send(embed=embed)
    else:
        embed = nextcord.Embed(title="You got kicked!",
                               description=f"You got kicked from {ctx.guild.name}, for {reason}! Better behave next time!",
                               color=0x2596be)
        await member.send(embed=embed)
        embed = nextcord.Embed(title="", description=f"Kicked {member.mention} for {reason}", color=0x2596be)
        await ctx.send(embed=embed)
        await member.kick(reason=reason)
Comment

PREVIOUS NEXT
Code Example
Python :: text replace 
Python :: nunique sort 
Python :: reverse row order padnas 
Python :: turtle meaning 
Python :: 1007 solution python 
Python :: pyqt line edit mouse position change 
Python :: disable json dumps encode 
Python :: Print all day-dates between two dates [duplicate] 
Python :: what does alpha in plt.txt do 
Python :: python gpsd client 
Python :: python empty array length n grepper 
Python :: ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’ meaning in resample 
Python :: discord py replace characters from string 
Python :: python strong type 
Python :: timestamp from date python 
Python :: Univariant Variable Analysis - Multiple Plots 
Python :: datetime 
Python :: python glob wildcard filename 
Python :: matplotlib add abline 
Python :: python os path join list 
Python :: Python Tkinter MenuButton Widget Syntax 
Python :: Difference between the remove() method and discard() method of sets in python 
Python :: how list ul info with python 
Python :: An error occurred while connecting: 10049: The requested address is not valid in its context.. scrapy splash 
Python :: running setup.py install for rjsmin ... error 
Python :: Call a function after every x seconds 
Python :: welcoming users using discord.py 
Python :: python recognize lower and upper case user input 
Python :: python Find Hash 
Python :: how to find the length of a list in python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =