I recently created a plugin that allows members of a certain group to create a reply with a certain command which leads to a bot (system user) closing a topic. I suggest you check it out:
While specific functions to make bots aren’t integrated into the core of Discourse, it should be relatively similar to the logic of creating a Discord bot.