So, I wanted to set up a purge command for discord.py, but everyone is able to use it. I obviously want it just for people who have the manage messages permission. I don't really understand ctx
commands yet, so I'd like to avoid that for now, and the only answers I can find to this involve using ctx
, and setting it up as @bot.command
. What I have right now is:
elif message.content.startswith ('jb!purge'):
searchargs = message.content.split(" ")
if(len(searchargs) > 1):
if(len(searchargs) > 2):
await message.channel.send("Too many numbers! Please try `jb!purge <number>`")
elif(len(searchargs) == 2):
if has_permissions(manage_messages = True):
try:
output = int(searchargs[1])
await message.channel.purge(limit=output)
except ValueError:
await message.channel.send("That's not a number, silly!")
else:
await message.channel.send("Go get the perms first, then try again.")
You can use TextChannel.permissions_for
using the TextChannel
object you have from Message.channel
. You can simply pass it the Member
object from Message.author
.
With the Permissions
object, you can then simply check Permissions.manage_messages
.
You should really look into using the commands extension though.
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.