Reputation: 35
@client.command()
@commands.has_permissions(administrator=True)
async def kick(ctx, member : discord.Member, *, reason=None):
try:
await member.kick(reason=reason)
embed = discord.Embed(colour=maincolour)
embed.title = f"**Member {member.mention} Kicked."
embed.description = f"**Reason** » {reason}.\n**Status** » Successful!"
await ctx.send(embed=embed)
except:
embed = discord.Embed(colour=maincolour)
embed.title = "**Kick not successful."
embed.description = "**Possible Errors:**\n» Insufficient Permissions (Requires Administrator)\n» Error with Bot."
await ctx.send(embed=embed)
On the line
@commands.has_permissions(administrator=True)
the error is 'Command' object has no attribute 'has_permissions'
.
How do I fix this error? This code works for my friend.
Upvotes: 2
Views: 1807
Reputation: 1318
The has_permissions
attribute doesn't go under commands. This is how this should be properly done.
from discord.ext.commands import has_permissions, MissingPermissions
@client.command()
@has_permissions(administrator = True)
async def test(ctx):
pass
@test.error
async def test_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.send("Looks like you don't have the permissions.")
Upvotes: 1