-
Notifications
You must be signed in to change notification settings - Fork 0
/
moderation.py
842 lines (786 loc) · 28.1 KB
/
moderation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
import datetime
import re
import discord
from discord.ext import commands
from helpers.embeds import Embeds
class Moderation(commands.Cog):
def __init__(self, bot: discord.Bot):
self.bot = bot
self.config = bot.config
self.log = bot.log
self.embed = Embeds()
@discord.slash_command(
name="invites",
description="View all active invites in the server",
)
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def _invites(self, ctx: discord.ApplicationContext):
invites = await ctx.guild.invites()
embed = discord.Embed(
title=f"Active Invites ({len(invites)})",
color=self.config["colors"]["info"],
)
for invite in invites:
embed.add_field(
name=invite.code,
value=f"**Creator**: {invite.inviter.mention}\n**Uses**: {invite.uses}\n**Channel**: {invite.channel.mention}",
)
await ctx.respond(embed=embed)
@discord.slash_command(name="kick", description="Kick a member from the guild")
@commands.has_permissions(kick_members=True)
@commands.guild_only()
async def kick(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
reason: discord.Option(str, "Reason for the kick", required=False),
):
try:
await ctx.guild.kick(member, reason=reason)
embed = discord.Embed(
title="Member Kicked", color=self.config["colors"]["success"]
)
embed.add_field(name="Member", value=member.mention, inline=False)
embed.add_field(
name="Reason", value=reason or "No reason provided", inline=False
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(
self.embed.error(f"Failed to kick {member}: {e}", ephemeral=True)
)
@discord.slash_command(
name="ban",
description="Ban a member from the guild",
)
@commands.has_permissions(ban_members=True)
@commands.guild_only()
async def ban(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
reason: discord.Option(str, "Reason for the ban", required=False),
):
try:
await ctx.guild.ban(member, reason=reason)
embed = discord.Embed(
title="Member Banned", color=self.config["colors"]["success"]
)
embed.add_field(name="Member", value=member.mention, inline=False)
embed.add_field(
name="Reason", value=reason or "No reason provided", inline=False
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(
self.embed.error(f"Failed to ban {member}: {e}", ephemeral=True)
)
@discord.slash_command(
name="lockdown",
description="Lockdown the current channel",
)
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def lockdown(
self,
ctx: discord.ApplicationContext,
reason: discord.Option(str, "Reason for the lockdown", required=False),
):
try:
await ctx.channel.set_permissions(
ctx.guild.default_role, send_messages=False
)
embed = discord.Embed(
title="Channel Locked",
description=f"The channel has been locked by {ctx.author.mention}.",
color=self.config["colors"]["success"],
)
embed.add_field(
name="Reason", value=reason or "No reason provided", inline=False
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(self.embed.error(f"Failed to lockdown channel: {e}"))
@discord.slash_command(
name="unlock",
description="Unlock the current channel",
)
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def unlock(self, ctx: discord.ApplicationContext):
try:
await ctx.channel.set_permissions(
ctx.guild.default_role, send_messages=True
)
embed = discord.Embed(
title="Channel Unlocked",
description=f"The channel has been unlocked by {ctx.author.mention}.",
color=self.config["colors"]["success"],
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(self.embed.error(f"Failed to unlock channel: {e}"))
@discord.slash_command(
name="moveall",
description="Move all members in a voice channel to another voice channel",
)
@commands.has_permissions(kick_members=True)
@commands.guild_only()
async def moveall(
self,
ctx: discord.ApplicationContext,
source: discord.Option(discord.VoiceChannel, "Select a source voice channel"),
destination: discord.Option(
discord.VoiceChannel, "Select a destination voice channel"
),
):
try:
moved_members = []
for member in source.members:
await member.move_to(destination)
moved_members.append(member)
await ctx.respond(
embed=self.embed.success(
f"Successfully moved {len(moved_members)} members from {source.mention} to {destination.mention}."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to move members: {e}"), ephemeral=True
)
@discord.slash_command(
name="timeout",
description="Mutes the selected member using Discord's timeout feature",
)
@commands.has_permissions(moderate_members=True)
@commands.guild_only()
async def timeout(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
duration: discord.Option(
str, "Duration of the timeout in hours", required=False, default=1
),
reason: discord.Option(str, "Reason for the timeout", required=False),
):
try:
duration = int(duration)
until = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(
hours=duration
)
await member.timeout(until=until, reason=reason)
embed = discord.Embed(
title="Member Timed Out",
description=f"{member.mention} has been timed out.",
color=self.config["colors"]["success"],
)
embed.add_field(name="Moderator", value=ctx.author.mention)
embed.add_field(
name="Duration",
value=f"{duration} hours",
)
embed.add_field(name="Reason", value=reason or "No reason provided")
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(
self.embed.error(f"Failed to timeout member: {e}"), ephemeral=True
)
@discord.slash_command(
name="untimeout",
description="Unmutes the selected member",
)
@commands.has_permissions(moderate_members=True)
@commands.guild_only()
async def untimeout(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
):
try:
await member.timeout(until=None)
embed = discord.Embed(
title="Member Timeout Removed",
description=f"{member.mention} has been untimed out by {ctx.author.mention}.",
color=self.config["colors"]["success"],
)
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(
self.embed.error(f"Failed to untimeout member: {e}"), ephemeral=True
)
@discord.slash_command(
name="imute",
description="Removes selected member's permission to attach files and use embed links",
)
@commands.has_permissions(moderate_members=True)
@commands.guild_only()
async def imute(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
reason: discord.Option(str, "Reason for the mute", required=False),
):
role_name = self.config["roles"]["media_muted"]
mute_role = discord.utils.get(ctx.guild.roles, name=role_name)
if mute_role is None:
try:
mute_permissions = discord.Permissions(
attach_files=False, embed_links=False
)
mute_role = await ctx.guild.create_role(
name=role_name, permissions=mute_permissions
)
except Exception as e:
return await ctx.respond(
embed=self.embed.error(f"Failed to create mute role: {e}"),
ephemeral=True,
)
try:
await member.add_roles(mute_role)
embed = discord.Embed(
title="Media Muted",
description=f"{member.mention} has been muted from sending attachments and embed links.",
color=self.config["colors"]["success"],
)
embed.add_field(name="Moderator", value=ctx.author.mention)
embed.add_field(name="Reason", value=reason or "No reason provided")
await ctx.respond(embed=embed)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to mute member: {e}"), ephemeral=True
)
@discord.slash_command(
name="iunmute",
description="Restores selected member'ss permission to attach files and use embed links",
)
@commands.has_permissions(moderate_members=True)
@commands.guild_only()
async def iunmute(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
):
role_name = self.config["roles"]["media_muted"]
mute_role = discord.utils.get(ctx.guild.roles, name=role_name)
if mute_role is None:
return await ctx.respond(
embed=self.embed.error("Mute role not found."), ephemeral=True
)
try:
await member.remove_roles(mute_role)
await ctx.respond(
embed=self.embed.success(
f"{member.mention} has been unmuted from sending attachments and embed links."
)
)
except Exception as e:
await ctx.respond(self.embed.error(f"Failed to unmute member: {e}"))
@discord.slash_command(
name="clearinvites",
description="Remove all existing invites from the guild",
)
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def clearinvites(self, ctx: discord.ApplicationContext):
try:
invites = await ctx.guild.invites()
for invite in invites:
await invite.delete()
await ctx.respond(
embed=self.embed.success(
f"Successfully cleared {len(invites)} invites."
)
)
except Exception as e:
await ctx.respond(self.embed.error(f"Failed to clear invites: {e}"))
_role = discord.commands.SlashCommandGroup(
name="role", description="Commands to manage roles"
)
@_role.command(
name="info",
description="Get information about a role",
)
@commands.guild_only()
async def info(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
):
# TODO: Implement role info command
pass
@_role.command(
name="add",
description="Add a role to a member",
)
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def add(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
role: discord.Option(discord.Role, "Select a role"),
):
try:
await member.add_roles(role)
await ctx.respond(
embed=self.embed.error(
f"Successfully added {role.mention} to {member.mention}."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to add role: {e}"), ephemeral=True
)
@_role.command(
name="remove",
description="Remove a role from a member",
)
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def remove(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
role: discord.Option(discord.Role, "Select a role"),
):
try:
await member.remove_roles(role)
await ctx.respond(
embed=self.embed.success(
f"Successfully removed {role.mention} from {member.mention}."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to remove role: {e}"), ephemeral=True
)
@_role.command(
name="color",
description="Changes a role's color, HEX value must be provided",
)
@commands.has_permissions(manage_roles=True)
@commands.guild_only()
async def color(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
color: discord.Option(str, "HEX value of the color"),
):
color = color.replace("#", "")
try:
await role.edit(color=discord.Color(int(color, 16)))
await ctx.respond(
embed=self.embed.success(
f"Successfully changed color of {role.mention}."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to change color: {e}"), ephemeral=True
)
@_role.command(
name="humans",
description="Add a role to all humans in the guild",
)
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def humans(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
):
try:
for member in ctx.guild.members:
if member.bot:
continue
await member.add_roles(role)
await ctx.respond(
embed=self.embed.success(
f"Successfully added {role.mention} to all humans."
),
ephemeral=True,
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to add role: {e}"), ephemeral=True
)
@_role.command(
name="humansremove",
description="Remove a role from all humans in the guild",
)
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def humansremove(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
):
try:
for member in ctx.guild.members:
if member.bot:
continue
await member.remove_roles(role)
await ctx.respond(
embed=self.embed.success(
f"Successfully removed {role.mention} from all humans."
),
ephemeral=True,
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to remove role: {e}"), ephemeral=True
)
@_role.command(
name="delete",
description="Delete a role from the guild",
)
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def delete(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
):
try:
await role.delete()
await ctx.respond(
embed=self.embed.success(f"Successfully deleted {role.mention}.")
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to delete role: {e}"), ephemeral=True
)
@_role.command(
name="mentionable",
description="Toggle mentioning a role",
)
@commands.has_permissions(manage_roles=True)
@commands.guild_only()
async def mentionable(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
):
try:
if role.mentionable:
await role.edit(mentionable=False)
await ctx.respond(
embed=self.embed.success(
f"Successfully disabled mentioning {role.mention}."
)
)
else:
await role.edit(mentionable=True)
await ctx.respond(
embed=self.embed.success(
f"Successfully enabled mentioning {role.mention}."
)
)
except Exception as e:
await ctx.respond(f"Failed to toggle mentionable: {e}")
@_role.command(
name="icon",
description="Set an icon for a role",
)
@commands.has_permissions(manage_roles=True)
@commands.guild_only()
async def icon(
self,
ctx: discord.ApplicationContext,
role: discord.Option(discord.Role, "Select a role"),
icon: discord.Option(discord.Attachment, "Attachment of the icon"),
):
try:
await role.edit(icon=await icon.read())
await ctx.respond(
embed=self.embed.success(f"Successfully set icon for {role.mention}.")
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to set icon: {e}"), ephemeral=True
)
_purge = discord.commands.SlashCommandGroup(
name="purge", description="Commands to purge messages"
)
@_purge.command(
name="amount",
description="Purge a specific amount of messages",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def amount(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
try:
deleted = await ctx.channel.purge(limit=amount)
await ctx.respond(
f"Successfully purged {len(deleted)} messages from the channel."
)
except Exception as e:
await ctx.respond(
f"Failed to purge messages: {e}",
ephemeral=True,
)
@_purge.command(
name="embeds",
description="Purge embeds from chat",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def embeds(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def is_embed(m):
return m.embeds
try:
deleted = await ctx.channel.purge(limit=amount, check=is_embed)
await ctx.respond(
f"Successfully purged {len(deleted)} messages with embeds."
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"),
ephemeral=True,
)
@_purge.command(
name="files",
description="Purge files/attachments from chat",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def files(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def is_file(m):
return m.attachments
try:
deleted = await ctx.channel.purge(limit=amount, check=is_file)
await ctx.respond(
embed=self.embed.success(
f"Successfully purged {len(deleted)} messages with files."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"),
ephemeral=True,
)
@_purge.command(
name="images",
description="Purge images (including links) from chat",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def images(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def is_image(msg):
if msg.attachments and any(
att.filename.lower().endswith(
(".png", ".jpg", ".jpeg", ".gif", ".webp")
)
for att in msg.attachments
):
return True
if msg.content:
url_regex = r"https?://[^\s]+"
urls = re.findall(url_regex, msg.content)
image_extensions = [".png", ".jpg", ".jpeg", ".gif", ".webp"]
for url in urls:
if url.lower().endswith(tuple(image_extensions)):
return True
return False
try:
deleted = await ctx.channel.purge(limit=amount, check=is_image)
await ctx.respond(
embed=self.embed.success(
f"Successfully purged {len(deleted)} messages with images."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"),
ephemeral=True,
)
@_purge.command(
name="contains",
description="Purge messages containing a string",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def contains(
self,
ctx: discord.ApplicationContext,
string: discord.Option(str, "String to search for"),
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def contains_string(m):
return string in m.content
try:
deleted = await ctx.channel.purge(limit=amount, check=contains_string)
await ctx.respond(
embed=self.embed.success(
f"Successfully purged {len(deleted)} messages that contained `{string}`."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"), ephemeral=True
)
@_purge.command(
name="links",
description="Purge messages containing links",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def links(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def contains_link(m):
url_regex = r"https?://[^\s]+"
urls = re.findall(url_regex, m.content)
return len(urls) > 0
try:
deleted = await ctx.channel.purge(limit=amount, check=contains_link)
await ctx.respond(
embed=self.embed.success(
f"Successfully purged {len(deleted)} messages containing links."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"), ephemeral=True
)
@_purge.command(
name="mentions",
description="Purge messages containing mentions",
)
@commands.has_permissions(manage_messages=True)
@commands.guild_only()
async def mentions(
self,
ctx: discord.ApplicationContext,
amount: discord.Option(
int, "Number of messages to purge", required=False, default=10
),
):
def contains_mention(m):
return len(m.mentions) > 0
try:
deleted = await ctx.channel.purge(limit=amount, check=contains_mention)
await ctx.respond(
embed=self.embed.success(
f"Successfully purged {len(deleted)} messages containing mentions."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to purge messages: {e}"), ephemeral=True
)
@discord.slash_command(
name="nuke",
description="Nuke (clone) the current channel",
)
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def nuke(self, ctx: discord.ApplicationContext):
try:
channel = await ctx.channel.clone()
await ctx.channel.delete()
await channel.send(self.config["nuke_image"])
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to nuke channel: {e}"), ephemeral=True
)
@discord.slash_command(
name="slowmode",
description="Set the slowmode for the current channel",
)
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def slowmode(
self,
ctx: discord.ApplicationContext,
seconds: discord.Option(
int,
"Number of seconds to set the slowmode to. (0 to disable)",
required=True,
),
):
try:
await ctx.channel.edit(slowmode_delay=seconds)
await ctx.respond(
embed=self.embed.success(
f"Successfully set slowmode to {seconds} seconds."
)
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to set slowmode: {e}"), ephemeral=True
)
@discord.slash_command(
name="rename",
description="Assigns the selected user a new nickname in the guild",
)
@commands.has_permissions(manage_nicknames=True)
@commands.guild_only()
async def rename(
self,
ctx: discord.ApplicationContext,
member: discord.Option(discord.Member, "Select a member"),
nickname: discord.Option(str, "New nickname for the member"),
):
try:
await member.edit(nick=nickname)
await ctx.respond(
embed=self.embed.success(f"Successfully renamed {member.mention}.")
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to rename member: {e}"), ephemeral=True
)
@discord.slash_command(
name="topic",
description="Sets the topic for the current channel",
)
@commands.has_permissions(manage_channels=True)
@commands.guild_only()
async def topic(
self,
ctx: discord.ApplicationContext,
topic: discord.Option(str, "New topic for the channel"),
):
try:
await ctx.channel.edit(topic=topic)
await ctx.respond(
embed=self.embed.success(f"Successfully set topic to `{topic}`.")
)
except Exception as e:
await ctx.respond(
embed=self.embed.error(f"Failed to set topic: {e}"), ephemeral=True
)
def setup(config: discord.Bot):
config.add_cog(Moderation(config))