Re-add missing kick command
This commit is contained in:
parent
df7df919d7
commit
969f041276
1 changed files with 68 additions and 67 deletions
|
@ -13,76 +13,77 @@ class KickCog(CacheCog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
|
||||||
|
@cog_ext.cog_slash(
|
||||||
@cog_ext.cog_slash(
|
name="kick",
|
||||||
name="kick",
|
description="Kick a user",
|
||||||
description="Kick a user",
|
options=[
|
||||||
options=[
|
create_option(
|
||||||
create_option(
|
name="user",
|
||||||
name="user",
|
description="User to kick",
|
||||||
description="User to kick",
|
option_type=6,
|
||||||
option_type=6,
|
required=True,
|
||||||
required=True,
|
),
|
||||||
),
|
create_option(
|
||||||
create_option(
|
name="reason",
|
||||||
name="reason",
|
description="Kick reason",
|
||||||
description="Kick reason",
|
required=False,
|
||||||
required=False,
|
option_type=3,
|
||||||
option_type=3,
|
),
|
||||||
),
|
],
|
||||||
],
|
|
||||||
)
|
|
||||||
@admin_or_permissions(kick_members=True)
|
|
||||||
async def _kick(self, ctx: SlashContext, user: User, reason=None):
|
|
||||||
if not user or user == ctx.author:
|
|
||||||
await ctx.send("You cannot kick yourself.", hidden=True)
|
|
||||||
return
|
|
||||||
if user == self.bot.user:
|
|
||||||
await ctx.send("I'm afraid I can't let you do that", hidden=True)
|
|
||||||
return
|
|
||||||
if len(reason) > 100:
|
|
||||||
await ctx.send("Reason must be < 100 characters", hidden=True)
|
|
||||||
return
|
|
||||||
if not reason:
|
|
||||||
reason = "Mr. Stark is displeased with your presence. Please leave."
|
|
||||||
guild_name = ctx.guild.name
|
|
||||||
embed = build_embed(
|
|
||||||
title=f"You have been kicked from {guild_name}",
|
|
||||||
description=f"Reason: {reason}",
|
|
||||||
fields=[],
|
|
||||||
)
|
)
|
||||||
|
@admin_or_permissions(kick_members=True)
|
||||||
|
async def _kick(self, ctx: SlashContext, user: User, reason=None):
|
||||||
|
if not user or user == ctx.author:
|
||||||
|
await ctx.send("You cannot kick yourself.", hidden=True)
|
||||||
|
return
|
||||||
|
if user == self.bot.user:
|
||||||
|
await ctx.send("I'm afraid I can't let you do that", hidden=True)
|
||||||
|
return
|
||||||
|
if len(reason) > 100:
|
||||||
|
await ctx.send("Reason must be < 100 characters", hidden=True)
|
||||||
|
return
|
||||||
|
if not reason:
|
||||||
|
reason = (
|
||||||
|
"Mr. Stark is displeased with your presence. Please leave."
|
||||||
|
)
|
||||||
|
guild_name = ctx.guild.name
|
||||||
|
embed = build_embed(
|
||||||
|
title=f"You have been kicked from {guild_name}",
|
||||||
|
description=f"Reason: {reason}",
|
||||||
|
fields=[],
|
||||||
|
)
|
||||||
|
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name=ctx.author.name + "#" + ctx.author.discriminator,
|
name=ctx.author.name + "#" + ctx.author.discriminator,
|
||||||
icon_url=ctx.author.avatar_url,
|
icon_url=ctx.author.avatar_url,
|
||||||
)
|
)
|
||||||
embed.set_thumbnail(ctx.guild.icon_url)
|
embed.set_thumbnail(ctx.guild.icon_url)
|
||||||
|
|
||||||
send_failed = False
|
send_failed = False
|
||||||
try:
|
try:
|
||||||
await user.send(embed=embed)
|
await user.send(embed=embed)
|
||||||
except Exception:
|
except Exception:
|
||||||
send_failed = True
|
send_failed = True
|
||||||
await ctx.guild.kick(user, reason=reason)
|
await ctx.guild.kick(user, reason=reason)
|
||||||
|
|
||||||
fields = [Field(name="DM Sent?", value=str(not send_failed))]
|
fields = [Field(name="DM Sent?", value=str(not send_failed))]
|
||||||
embed = build_embed(
|
embed = build_embed(
|
||||||
title="User Kicked",
|
title="User Kicked",
|
||||||
description=f"Reason: {reason}",
|
description=f"Reason: {reason}",
|
||||||
fields=fields,
|
fields=fields,
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name=user.nick if user.nick else user.name,
|
name=user.nick if user.nick else user.name,
|
||||||
icon_url=user.avatar_url,
|
icon_url=user.avatar_url,
|
||||||
)
|
)
|
||||||
embed.set_thumbnail(url=user.avatar_url)
|
embed.set_thumbnail(url=user.avatar_url)
|
||||||
embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}")
|
embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}")
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
_ = Kick(
|
_ = Kick(
|
||||||
user=user.id,
|
user=user.id,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
admin=ctx.author.id,
|
admin=ctx.author.id,
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
).insert()
|
).insert()
|
||||||
|
|
Loading…
Add table
Reference in a new issue