简体   繁体   中英

Checking if bot is permitted to send and read messages in a channel discord.py

How can I check if my bot is allowed to send and read messages in a specific channel? My code right now is:

channel = client.get_channel('''channel id''')
print(channel.permissions_for(client.user))

But the resulting error is in the abc.py part of discord and it says:

print(channel.permissions_for(client.user))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/channel.py", line 146, in permissions_for
    base = super().permissions_for(member)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/abc.py", line 486, in permissions_for
    roles = member._roles
AttributeError: 'ClientUser' object has no attribute '_roles'

Even though the bot does have the "bots" role. Any input would be much appreciated. Thanks!

I recommend you to read the [has_permission] documentation and the [permission_property] fully and clearly.
It will answer your queries!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM