File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
commanderbot_ext/ext/kick Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ from discord .ext import commands
2+
3+ from commanderbot_ext .ext .kick .kick_cog import KickCog
4+
5+
6+ def setup (bot : commands .Bot ):
7+ bot .add_cog (KickCog (bot ))
Original file line number Diff line number Diff line change 1+ import logging
2+ from typing import Optional
3+
4+ from discord import Member
5+ from discord .ext .commands import Bot , Cog , Context , command
6+
7+ LOG = logging .getLogger (__name__ )
8+
9+
10+ class KickCog (Cog , name = "commanderbot_ext.ext.kick" ):
11+ def __init__ (self , bot : Bot ):
12+ self .bot : Bot = bot
13+
14+ @command (name = "kick" )
15+ async def cmd_kick (
16+ self ,
17+ ctx : Context ,
18+ user : Member ,
19+ * ,
20+ reason : Optional [str ] = None ,
21+ ):
22+ # make sure we aren't trying to kick the bot itself
23+ if user == self .bot .user :
24+ await ctx .reply ("I don't think you want to do that..." )
25+ LOG .warning ("Tried to kick the bot itself" )
26+ return
27+
28+ # attempt to DM if a reason was included
29+ # we do this before kicking in case this is the only mutual server
30+ if reason :
31+ try :
32+ await user .send (
33+ content = f"You were kicked from **{ ctx .guild } ** for:\n >>> { reason } " ,
34+ )
35+ await ctx .message .add_reaction ("✉️" )
36+ except :
37+ LOG .exception (f"Failed to DM { user } about being kicked" )
38+ else :
39+ LOG .info (f"Successfully DM'd { user } about being kicked" )
40+
41+ # actually kick the user
42+ try :
43+ await user .kick (reason = reason )
44+ await ctx .message .add_reaction ("👢" )
45+ except :
46+ LOG .exception (f"Failed to kick { user } " )
47+ else :
48+ LOG .info (f"Successfully kicked { user } " )
You can’t perform that action at this time.
0 commit comments