3
3
"""
4
4
5
5
import discord .ext .commands as commands
6
+ import discord .ui as UI
6
7
import helpers
7
8
import asyncio
8
9
import discord
10
+ import start
9
11
import json
10
12
11
13
14
16
15
17
@commands .command ()
16
18
@commands .has_permissions (manage_messages = True )
17
- async def clear (ctx : commands .Context , amount : int ):
19
+ @commands .cooldown (1 , 15 , commands .BucketType .user )
20
+ async def clear (ctx : commands .Context , amount : int | None ):
18
21
"""
19
22
Clears messages from a text channel.
20
23
@@ -27,11 +30,35 @@ async def clear(ctx: commands.Context, amount: int):
27
30
amount (int):
28
31
The number of messages to clear.
29
32
"""
30
- await ctx .channel .purge (limit = amount )
33
+ if amount is not None : # If the user selected an amount, clear that amount of messages
34
+ await ctx .send (embed = discord .Embed (title = f'🛠️ Deleting **{ amount } ** messages.' ))
35
+ return await ctx .channel .purge (limit = amount )
36
+
37
+ # Else, create two buttons
38
+ # Then ask the user if they would like to clear all messages in the channel
39
+ yes_button = UI .Button (label = 'Yes' , style = discord .ButtonStyle .green )
40
+ no_button = UI .Button (label = 'No' , style = discord .ButtonStyle .red )
41
+
42
+ yes_button .callback = lambda interaction : \
43
+ (await interaction .channel .purge (limit = None ) for _ in '_' ).__anext__ ()
44
+ no_button .callback = lambda interaction : \
45
+ (await interaction .message .delete () for _ in '_' ).__anext__ ()
46
+
47
+ view = UI .View ()
48
+ view .add_item (yes_button )
49
+ view .add_item (no_button )
50
+
51
+ return await ctx .send (
52
+ f':warning: { ctx .author .mention } : You have not selected a number of messages to clear.\n '
53
+ + 'Would you like to clear all messages in this channel?' ,
54
+ view = view
55
+ )
56
+
31
57
32
58
33
59
@commands .command ()
34
60
@commands .has_permissions (kick_members = True )
61
+ @commands .cooldown (1 , 30 , commands .BucketType .user )
35
62
async def kick (ctx : commands .Context , member : discord .Member , * , reason = None ):
36
63
"""
37
64
Kicks a specified member from a server.
@@ -53,6 +80,7 @@ async def kick(ctx: commands.Context, member: discord.Member, *, reason=None):
53
80
54
81
@commands .command ()
55
82
@commands .has_permissions (ban_members = True )
83
+ @commands .cooldown (1 , 30 , commands .BucketType .user )
56
84
async def ban (ctx : commands .Context , member : discord .Member , * , reason = None ):
57
85
"""
58
86
Bans a specified member from a server.
@@ -74,6 +102,7 @@ async def ban(ctx: commands.Context, member: discord.Member, *, reason=None):
74
102
75
103
@commands .command ()
76
104
@commands .has_permissions (ban_members = True )
105
+ @commands .cooldown (1 , 30 , commands .BucketType .user )
77
106
async def softban (ctx : commands .Context , member : discord .Member , days = 1 , reason = None ):
78
107
"""
79
108
Temporarily bans a specified member from a server.
@@ -99,6 +128,7 @@ async def softban(ctx: commands.Context, member: discord.Member, days=1, reason=
99
128
100
129
@commands .command ()
101
130
@commands .has_permissions (ban_members = True )
131
+ @commands .cooldown (1 , 2 , commands .BucketType .user )
102
132
async def unban (ctx : commands .Context , user : discord .User ):
103
133
"""
104
134
Unbans a specified user from a server.
@@ -117,6 +147,7 @@ async def unban(ctx: commands.Context, user: discord.User):
117
147
118
148
@commands .command ()
119
149
@commands .has_permissions (manage_messages = True )
150
+ @commands .cooldown (1 , 2 , commands .BucketType .user )
120
151
async def blacklist (ctx : commands .Context , * , word : str ):
121
152
"""
122
153
Adds a word to a list of disallowed words in a server.
@@ -133,7 +164,7 @@ async def blacklist(ctx: commands.Context, *, word: str):
133
164
filepath = 'files/blacklist.json'
134
165
id = str (ctx .guild .id )
135
166
136
- with open (filepath , "r" ) as file :
167
+ with open (filepath , 'r' ) as file :
137
168
blacklist : dict = json .load (file )
138
169
139
170
if id not in blacklist .keys ():
@@ -147,7 +178,8 @@ async def blacklist(ctx: commands.Context, *, word: str):
147
178
148
179
with open (filepath , 'w' ) as file :
149
180
json .dump (blacklist , file , indent = 4 )
150
- await ctx .send (f':tools: \' { word } \' has been added to the blacklist.' )
181
+
182
+ await ctx .send (f':tools: \' { word } \' has been added to the blacklist.' )
151
183
152
184
153
185
# |----- REGISTERING MODULE -----|
0 commit comments