Search code examples
pythondiscord.py

How do i detect a tag on a post in forums channel in discord.py?


I searched through the internet and I couldn't find the answer I am asking here.

I want to make it so when a new post is created in a forum, the bot checks its tags, and depending on which tags it has. It will add a link to the post to a list of links to be later posted via a slash command. How do I make a bot to detect the tags that are attached to the post?


Solution

  • The posts you see on a Forum Channel are actually Threads. You can get the tags of a thread like this:

    your_forum_channel.threads[0].applied_tags
    

    You can find more on the documentation: https://discordpy.readthedocs.io/en/stable/api.html?highlight=forumchannel#discord.Thread.applied_tags

    Given what you want to do, this is probably what you want to do

    @bot.event
    async def on_thread_create(thread :discord.Thread):
        if thread.parent_id == your_forum_channel_id:
             tags = thread.applied_tags