How do I check if my Python Discord bot has the necessary permissions?
User
objects don't have server permissions, Member
objects do. (Because a User
can be a Member
of multiple servers, with different permissions in each) To get the Member
object representing your bot on a particular server, use Server.me
. So for all of your examples, change
client.user.server_permissions
to
message.channel.server.me.server_permissions
Check if bot has enough permissions (or handle it)
You could add a general error handler for the Forbidden
error, which discord.py raises on a 403 Forbidden: Missing Permissions
error. You need to unpack it first from the general CommandInvokeError
before.
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandInvokeError):
error = error.original
if isinstance(error, discord.errors.Forbidden):
await ctx.send("Whatever you want to say here.")
How to allow command with one discord.py check?
I found an answer! After reviewing the docs, I found the @commands.check_any()
decorator. You can input checks for it to check, and if any of the inputted checks will be passed, it adds that check.
Read more about this decorator in the documentation.
Discord.py using multiple permission check decorators on command methods
You can use the commands.check_any
decorator
@client.command()
@commands.check_any(commands.is_owner(), commands.has_permissions(manage_channels=True))
async def ...
Reference:
commands.check_any
Related Topics
Python Multiprocessing Pool Hangs At Join
How Can My Model Primary Key Start With a Specific Number
Get Character Position in Alphabet
Tf.Data.Dataset: How to Get the Dataset Size (Number of Elements in an Epoch)
Python - Converting a List of 2 Digit String Numbers to a List of 2 Digit Integers
Replace Only Exactly Matching String Python Ndarry
How to Calculate a Gaussian Kernel Matrix Efficiently in Numpy
How Do Convert a Pandas Dataframe to Xml
How to Find Factors of a Number Using the Simplest Python Method
Split List into Two Parts Based on Some Delimiter in Each List Element in Python
Animate a Rotating 3D Graph in Matplotlib
Pickle - Cpickle.Unpicklingerror: Invalid Load Key, '?'
Pandas - Calculate Average of Columns With Condition Based on Values in Other Columns
Adding Months to a Pandas Object in Python
Insert Comma into Text File Using Python
Print the Lines of a Log File Which Starts With Date Format "Yyyy-Mm-Dd" in Python