Skip to content

Commit eeeca25

Browse files
committed
Add close command for threads/posts
The command will close the thread (if on a text channel), and archive the post (if on a forum channel). When in a forum channel, the command will look for a tag from that specific forum called 'done' (each tag will have different IDs depending on the forum) and apply to the post if found. The bot will send a message notifying who closed it.
1 parent 3512a27 commit eeeca25

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

intbot/core/bot/main.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,40 @@ async def wiki(ctx):
3838
suppress_embeds=True,
3939
)
4040

41+
@bot.command()
42+
async def close(ctx):
43+
channel = ctx.channel
44+
parent = channel.parent
45+
author = ctx.message.author
46+
47+
# Check if it's a public or private post (thread)
48+
if channel.type in (discord.ChannelType.public_thread, discord.ChannelType.private_thread):
49+
50+
# Check if the post (thread) was sent in a forum,
51+
# so we can add a tag
52+
if parent.type == discord.ChannelType.forum:
53+
54+
# Get tag from forum
55+
tag = None
56+
for _tag in parent.available_tags:
57+
if _tag.name.lower() == "done":
58+
tag = _tag
59+
break
60+
61+
if tag is not None:
62+
await channel.add_tags(tag)
63+
64+
# Remove command message
65+
await ctx.message.delete()
66+
67+
# We need to archive after adding tags in case it was a forum.
68+
# Otherwise we only archive the thread
69+
await channel.edit(archived=True)
70+
71+
# Send notification to the thread
72+
await channel.send(f"# This was marked as done by {author.mention}")
73+
74+
4175

4276
@bot.command()
4377
async def version(ctx):

0 commit comments

Comments
 (0)