Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to limit a command to a permission in discord.py

# Make sure you don't have a command called "commands"
@client.command() # As usual
@commands.has_permissions(administrator=True) # Making sure the person executing the command has the permissions
async def foo(ctx):
	await ctx.send("Hello")
    #ect
Comment

discord.py how to use permissions

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)
async def _kick(ctx, member: Member):
    await bot.kick(member)

@_kick.error
async def kick_error(error, ctx):
    if isinstance(error, MissingPermissions):
        text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
        await bot.send_message(ctx.message.channel, text)
Comment

discord.py permissions

@bot.command()
@commands.has_permissions(manage_messages=True)
async def test(ctx):
    await ctx.send('You can manage messages.')
   
# https://discordpy.readthedocs.io/en/stable/api.html#discord.Permissions
Comment

PREVIOUS NEXT
Code Example
Python :: set cookie in python requests 
Python :: export_excel file python 
Python :: how to print on python 
Python :: data dictionary python into numpy 
Python :: star operator python 
Python :: pygame holding a button down 
Python :: fibonacci sequence python 
Python :: python program running time 
Python :: colab pip 
Python :: mob psycho 100 
Python :: blank=True 
Python :: word pattern python 
Python :: python get current time 
Python :: shutil move overwrite 
Python :: python image to grayscale 
Python :: convert image to black and white python 
Python :: generics python 
Python :: how to read a text file from url in python 
Python :: tkinter button foreground color click 
Python :: pandas drop na in column 
Python :: python if else one line 
Python :: pyttsx3 install 
Python :: how to kill tkinter 
Python :: calculate nth prime number python 
Python :: python get position of character in string 
Python :: how to do date time formatting with strftime in python 
Python :: tkinter how to move button 
Python :: natural log and log base 10 in python 
Python :: pyinstaller command 
Python :: how to convert types of variablesin python 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =