How do I restrict discord bot commands to the bot owner or administrator permissions?

Viewed 2041

Ok, So I have a bot that on every command I write @commands.has_permissions(administrator = True) But now I want to do some commands in the dm's, however when I go to do that the bot throws an error and says I don't have the administrator permission. I can change the line to @commands.is_owner() but then only I can do it, so then I tried using both but it still only worked for me. I have searched everywhere but turned up nothing. So my question is... How can I tell the bot to respond to either an admin or myself(the owner)?

Here is my test function where I left off.

@bot.command(name="ping")                                           
@commands.has_permissions(administrator = True)
async def ping(ctx):
    await ctx.channel.send("pong")
1 Answers
@bot.command(name="ping")                                           
async def ping(ctx):
    user = ctx.author
    if await bot.is_owner(user):
       await ctx.channel.send("pong")
       return
    roles = user.roles
    for role in roles:
        if role.Permissions.administrator:
           await ctx.channel.send("pong")
           return

Related