Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic thread creation #21

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
23 changes: 21 additions & 2 deletions discord/events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -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;


Expand Down