diff --git a/README.md b/README.md index dd28289..af25c5b 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ We welcome you to make this first step and make your first pull request today. # 5. Contributors - [Tuomas Jääsalo](https://github.com/alcjzk) +- [Eemil Majuri](https://github.com/CrispLake) (add your name above if you contribute and a link to your github) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index 4e841ab..17738cb 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -1,11 +1,30 @@ -const { Events } = require('discord.js'); +const { Events, ChannelType, MessageType } = require('discord.js'); const { prefix } = require('../config.json'); +const autoThreadEnabled = (client, message) => { + const channel = message.channel; + if (channel.type === ChannelType.GuildText && message.type === MessageType.Default) { + if (client.config.autoThreadChannels && client.config.autoThreadChannels.includes(channel.id)) return true; + } + return false; +}; + +const startThread = async (message) => { + await message.startThread({ + name: message.content.length > 0 ? message.content.substring(0, 99) : message.member.displayName + '\'s thread' + }) +} + module.exports = { name: Events.MessageCreate, async execute(message, client) { if (message.author.bot) return; - if (message.content.indexOf(prefix) !== 0) return; + if (message.content.indexOf(prefix) !== 0) { + if (autoThreadEnabled(client, message) === true) { + await startThread(message); + } + return; + } if (client.helpers.channelsAuth.authorizedCommandLocations(client, message) === false) return;