From 808bc2e3f849ec158cee99bceb785425e5005c8b Mon Sep 17 00:00:00 2001 From: CrispLake Date: Sun, 25 Jun 2023 02:56:54 +0300 Subject: [PATCH 1/6] Added automatic threading option Channels that are added in config inside autoThreadChannels field will have the bot starting thread to all non command messages --- discord/events/messageCreate.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index 4e841ab..9377d7b 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -1,11 +1,30 @@ -const { Events } = require('discord.js'); +const { Events, ChannelType } = require('discord.js'); const { prefix } = require('../config.json'); +const autoThreadEnabled = (client, message) => { + const channel = message.channel; + if (channel.type === ChannelType.GuildText) { + if (client.config.autoThreadChannels && client.config.autoThreadChannels.includes(channel.id)) { return true; } + } + return false; +}; + +const startThread = async (message) => { + await message.startThread({ + name: message.content.substring(0, 99) + }) +} + 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; From c45d3144da3029129a6d9b3fd184f3549bde271a Mon Sep 17 00:00:00 2001 From: CrispLake Date: Sun, 25 Jun 2023 03:10:03 +0300 Subject: [PATCH 2/6] Removed braces from return to be consistent with the file --- discord/events/messageCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index 9377d7b..e4c832c 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -4,7 +4,7 @@ const { prefix } = require('../config.json'); const autoThreadEnabled = (client, message) => { const channel = message.channel; if (channel.type === ChannelType.GuildText) { - if (client.config.autoThreadChannels && client.config.autoThreadChannels.includes(channel.id)) { return true; } + if (client.config.autoThreadChannels && client.config.autoThreadChannels.includes(channel.id)) return true; } return false; }; From 38b3b13f02d1d107f493f41b37ec0c359231deeb Mon Sep 17 00:00:00 2001 From: CrispLake Date: Sun, 25 Jun 2023 17:31:34 +0300 Subject: [PATCH 3/6] Added my name to the contributors list --- README.md | 1 + 1 file changed, 1 insertion(+) 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) From a276127d23c3b5afa368cca1cd06276df67877fb Mon Sep 17 00:00:00 2001 From: CrispLake Date: Sun, 25 Jun 2023 18:36:19 +0300 Subject: [PATCH 4/6] Fixed the bot trying to start a thread if the initial message was a thread --- discord/events/messageCreate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index e4c832c..9744964 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -1,9 +1,9 @@ -const { Events, ChannelType } = 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) { + if (channel.type === ChannelType.GuildText && message.type === MessageType.Default) { if (client.config.autoThreadChannels && client.config.autoThreadChannels.includes(channel.id)) return true; } return false; From b50dae87e0b7960029c96da3eaffb04abc97d81a Mon Sep 17 00:00:00 2001 From: CrispLake Date: Sun, 25 Jun 2023 18:42:07 +0300 Subject: [PATCH 5/6] Fixed the bot not creating thread to a message that has only a file --- discord/events/messageCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index 9744964..ef65d1b 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -11,7 +11,7 @@ const autoThreadEnabled = (client, message) => { const startThread = async (message) => { await message.startThread({ - name: message.content.substring(0, 99) + name: message.content.length > 0 ? message.content.substring(0, 99) : message.member.nickname + '\'s thread' }) } From db32c4fec659d6de482606c13089a3dfd954ce74 Mon Sep 17 00:00:00 2001 From: Eemil Majuri Date: Thu, 29 Jun 2023 13:42:34 +0300 Subject: [PATCH 6/6] Changed .nickname to .displayName because displayname gives nickname or username if nickname doesn't exist --- discord/events/messageCreate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/events/messageCreate.js b/discord/events/messageCreate.js index ef65d1b..17738cb 100644 --- a/discord/events/messageCreate.js +++ b/discord/events/messageCreate.js @@ -11,7 +11,7 @@ const autoThreadEnabled = (client, message) => { const startThread = async (message) => { await message.startThread({ - name: message.content.length > 0 ? message.content.substring(0, 99) : message.member.nickname + '\'s thread' + name: message.content.length > 0 ? message.content.substring(0, 99) : message.member.displayName + '\'s thread' }) }