add members to thread

case "adduser": {
            await interaction.reply({ content: `Please provide the ID of the user you want to add to the thread.`, ephemeral: bot.config.discordConfig.ephemeral });
        
            const filter = m => m.author.id === interaction.user.id;
            const collector = interaction.channel.createMessageCollector({ filter, time: 1500000 });
            const thread = interaction.channel;
        
            if (!thread) {
                return interaction.reply({ content: 'Thread not found.', ephemeral: true });
            }
        
            collector.on('collect', async (m) => {
                if (m.content.toLowerCase() === bot.language.cancel) {
                    await m.delete().catch(() => { });
                    collector.stop();
                    return interaction.reply({ content: language.ticketMaxTickets.cancel, ephemeral: bot.config.discordConfig.ephemeral }).catch(() => { });
                }
        
                const userId = m.content.trim();
                const userToAdd = interaction.guild.members.cache.get(userId);
    
                if (!userToAdd) { 
                    return interaction.followUp('User not found or invalid ID.');
                }
                try {
                    await thread.members.add(userToAdd.user.id);
                    interaction.channel.send(`User ${userToAdd.user.tag} added to thread ${thread.id} successfully.`);
                } catch (error) {
                    console.error('Error adding user to thread:', error);
                    interaction.channel.send('Error adding user to thread. Please try again later.');
                }
        
                collector.stop();
            });
        
            collector.on('end', (collected, reason) => {
                if (reason === 'time') {
                    interaction.followUp('No response received. Command timed out.');
                }
            });
        
            break;
        }
Was this page helpful?