Reputation: 475
I'm creating a new bot (my third time now, but it's been a while) and I am creating a simple ban command. It is line-for-line the same as my other commands, with the addition of the @commands.has_permissions()
decorator and an embed to display the ban. However, after adding some prints to show where it gets to, it doesn't make it past await user.ban()
.
# ---BAN---
@client.command(name="ban", pass_ctx=True)
@commands.has_permissions(ban_members=True)
async def ban(ctx, user: discord.User=None, *, reason: str=None):
if not user:
await ctx.send("Specify a user")
return
embed = discord.Embed (
color = discord.Color.magenta()
)
embed.add_field(name=f"{user} was banned!", value=f"For reason: {reason}", inline=False)
await user.ban()
await ctx.send(embed=embed)
@ban.error
async def ban_error(ctx, error):
if isinstance(error, BadArgument):
await ctx.send("Please specify a **valid** user!")
No error is thrown, but it only gets to await user.ban()
before just stopping. Is my user wrong somehow, or did I make an obvious mistake?
Upvotes: 0
Views: 59
Reputation: 795
'User' object has no attribute 'ban' , instead you need to pass a member object:
async def ban(ctx, user: discord.Member=None, *, reason: str=None):
And you're not getting any errors because @ban.error
is catching them but is only handling the BadArgument
exception while the rest are ignored.
Upvotes: 1